已合并
新增web嵌套滚动前后模式不一致规格 #22331
zhufenghao创建于 2023年11月24日
新增web嵌套滚动前后模式不一致规格 #22331
已合并
从refs/pull/22331/head合入到master
共 2 个文件变更+29-32
| @@ -2572,6 +2572,7 @@ ScrollResult WebPattern::HandleScroll(float offset, int32_t source, NestedState | |||
| 2572 | TAG_LOGD(AceLogTag::ACE_WEB, "WebPattern::HandleScroll offset = %{public}f", offset); | 2572 | TAG_LOGD(AceLogTag::ACE_WEB, "WebPattern::HandleScroll offset = %{public}f", offset); |
| 2573 | auto parent = parent_.Upgrade(); | 2573 | auto parent = parent_.Upgrade(); |
| 2574 | if (parent) { | 2574 | if (parent) { |
| 2575 | + source = isMouseEvent_ ? SCROLL_FROM_AXIS : source; | ||
| 2575 | return parent->HandleScroll(offset, source, state); | 2576 | return parent->HandleScroll(offset, source, state); |
| 2576 | } | 2577 | } |
| 2577 | return { 0.0f, false }; | 2578 | return { 0.0f, false }; |
| @@ -2581,11 +2582,9 @@ bool WebPattern::HandleScrollVelocity(float velocity) | |||
| 2581 | { | 2582 | { |
| 2582 | TAG_LOGD(AceLogTag::ACE_WEB, "WebPattern::HandleScrollVelocity velocity = %{public}f", velocity); | 2583 | TAG_LOGD(AceLogTag::ACE_WEB, "WebPattern::HandleScrollVelocity velocity = %{public}f", velocity); |
| 2583 | auto parent = parent_.Upgrade(); | 2584 | auto parent = parent_.Upgrade(); |
| 2584 | - if (parent) { | 2585 | + if (parent && parent->HandleScrollVelocity(velocity)) { |
| 2585 | - if (parent->HandleScrollVelocity(velocity)) { | 2586 | + TAG_LOGD(AceLogTag::ACE_WEB, "Parent component successfully called HandleScrollVelocity"); |
| 2586 | - TAG_LOGI(AceLogTag::ACE_WEB, "Parent component successfully called HandleScrollVelocity"); | 2587 | + return true; |
| 2587 | - return true; | ||
| 2588 | - } | ||
| 2589 | } | 2588 | } |
| 2590 | return false; | 2589 | return false; |
| 2591 | } | 2590 | } |
| @@ -2612,17 +2611,18 @@ void WebPattern::OnScrollEndRecursive() | |||
| 2612 | void WebPattern::OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling) | 2611 | void WebPattern::OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling) |
| 2613 | { | 2612 | { |
| 2614 | float velocity = GetAxis() == Axis::HORIZONTAL ? xVelocity : yVelocity; | 2613 | float velocity = GetAxis() == Axis::HORIZONTAL ? xVelocity : yVelocity; |
| 2615 | - if (nestedScrollMode_ != NestedScrollMode::SELF_FIRST) { | 2614 | + if (!isFling) { |
| 2616 | - return; | 2615 | + if (scrollState_ && ((velocity < 0 && nestedScrollForwardMode_ == NestedScrollMode::SELF_FIRST) || |
| 2617 | - } | 2616 | + (velocity > 0 && nestedScrollBackwardMode_ == NestedScrollMode::SELF_FIRST))) { |
| 2618 | - if (isFling) { | 2617 | + HandleScroll(-velocity, SCROLL_FROM_UPDATE, NestedState::CHILD_SCROLL); |
| 2619 | - if (velocity != 0 && isFirstFlingScrollVelocity_) { | ||
| 2620 | - HandleScrollVelocity(velocity); | ||
| 2621 | - isFirstFlingScrollVelocity_ = false; | ||
| 2622 | } | 2618 | } |
| 2623 | } else { | 2619 | } else { |
| 2624 | - if (scrollState_) { | 2620 | + if (((velocity > 0 && nestedScrollForwardMode_ == NestedScrollMode::SELF_FIRST) || |
| 2625 | - HandleScroll(-velocity, SCROLL_FROM_UPDATE, NestedState::CHILD_SCROLL); | 2621 | + (velocity < 0 && nestedScrollBackwardMode_ == NestedScrollMode::SELF_FIRST))) { |
| 2622 | + if (isFirstFlingScrollVelocity_) { | ||
| 2623 | + HandleScrollVelocity(velocity); | ||
| 2624 | + isFirstFlingScrollVelocity_ = false; | ||
| 2625 | + } | ||
| 2626 | } | 2626 | } |
| 2627 | } | 2627 | } |
| 2628 | } | 2628 | } |
| @@ -2680,35 +2680,31 @@ void WebPattern::OnRootLayerChanged(int width, int height) | |||
| 2680 | 2680 | ||
| 2681 | void WebPattern::SetNestedScroll(const NestedScrollOptions& nestedOpt) | 2681 | void WebPattern::SetNestedScroll(const NestedScrollOptions& nestedOpt) |
| 2682 | { | 2682 | { |
| 2683 | - if (nestedOpt.forward == NestedScrollMode::SELF_ONLY && | 2683 | + nestedScrollForwardMode_ = nestedOpt.forward; |
| 2684 | - nestedOpt.backward == NestedScrollMode::SELF_ONLY) { | 2684 | + nestedScrollBackwardMode_ = nestedOpt.backward; |
| 2685 | - nestedScrollMode_ = NestedScrollMode::SELF_ONLY; | 2685 | + TAG_LOGD(AceLogTag::ACE_WEB, |
| 2686 | - } else if (nestedOpt.forward == NestedScrollMode::SELF_FIRST && | 2686 | + "SetNestedScroll nestedScrollForwardMode_ = %{public}d, nestedScrollBackwardMode_ = %{public}d", |
| 2687 | - nestedOpt.backward == NestedScrollMode::SELF_FIRST) { | 2687 | + nestedScrollForwardMode_, nestedScrollBackwardMode_); |
| 2688 | - nestedScrollMode_ = NestedScrollMode::SELF_FIRST; | ||
| 2689 | - } else if (nestedOpt.forward == NestedScrollMode::PARENT_FIRST && | ||
| 2690 | - nestedOpt.backward == NestedScrollMode::PARENT_FIRST) { | ||
| 2691 | - nestedScrollMode_ = NestedScrollMode::PARENT_FIRST; | ||
| 2692 | - } else if (nestedOpt.forward == NestedScrollMode::PARALLEL && | ||
| 2693 | - nestedOpt.backward == NestedScrollMode::PARALLEL) { | ||
| 2694 | - nestedScrollMode_ = NestedScrollMode::PARALLEL; | ||
| 2695 | - } | ||
| 2696 | - TAG_LOGD(AceLogTag::ACE_WEB, "SetNestedScroll %{public}d", nestedScrollMode_); | ||
| 2697 | } | 2688 | } |
| 2698 | 2689 | ||
| 2699 | bool WebPattern::FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity) | 2690 | bool WebPattern::FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity) |
| 2700 | { | 2691 | { |
| 2701 | float offset = GetAxis() == Axis::HORIZONTAL ? x : y; | 2692 | float offset = GetAxis() == Axis::HORIZONTAL ? x : y; |
| 2702 | float velocity = GetAxis() == Axis::HORIZONTAL ? xVelocity : yVelocity; | 2693 | float velocity = GetAxis() == Axis::HORIZONTAL ? xVelocity : yVelocity; |
| 2703 | - if (nestedScrollMode_ == NestedScrollMode::PARENT_FIRST) { | 2694 | + if (((offset > 0 || velocity > 0) && nestedScrollForwardMode_ == NestedScrollMode::PARENT_FIRST) || |
| 2695 | + ((offset < 0 || velocity < 0) && nestedScrollBackwardMode_ == NestedScrollMode::PARENT_FIRST)) { | ||
| 2704 | if (offset != 0) { | 2696 | if (offset != 0) { |
| 2705 | auto result = HandleScroll(offset, SCROLL_FROM_UPDATE, NestedState::CHILD_SCROLL); | 2697 | auto result = HandleScroll(offset, SCROLL_FROM_UPDATE, NestedState::CHILD_SCROLL); |
| 2706 | TAG_LOGD(AceLogTag::ACE_WEB, "FilterScrollEvent ScrollBy remainOffset = %{public}f", result.remain); | 2698 | TAG_LOGD(AceLogTag::ACE_WEB, "FilterScrollEvent ScrollBy remainOffset = %{public}f", result.remain); |
| 2707 | - return NearZero(result.remain); | 2699 | + CHECK_NULL_RETURN(delegate_, false); |
| 2700 | + GetAxis() == Axis::HORIZONTAL ? delegate_->ScrollBy(-result.remain, 0) | ||
| 2701 | + : delegate_->ScrollBy(0, -result.remain); | ||
| 2702 | + return true; | ||
| 2708 | } else { | 2703 | } else { |
| 2709 | return HandleScrollVelocity(velocity); | 2704 | return HandleScrollVelocity(velocity); |
| 2710 | } | 2705 | } |
| 2711 | - } else if (nestedScrollMode_ == NestedScrollMode::PARALLEL) { | 2706 | + } else if (((offset > 0 || velocity > 0) && nestedScrollForwardMode_ == NestedScrollMode::PARALLEL) || |
| 2707 | + ((offset < 0 || velocity < 0) && nestedScrollBackwardMode_ == NestedScrollMode::PARALLEL)) { | ||
| 2712 | if (offset != 0) { | 2708 | if (offset != 0) { |
| 2713 | HandleScroll(offset, SCROLL_FROM_UPDATE, NestedState::CHILD_SCROLL); | 2709 | HandleScroll(offset, SCROLL_FROM_UPDATE, NestedState::CHILD_SCROLL); |
| 2714 | } else { | 2710 | } else { |
| @@ -638,7 +638,8 @@ private: | |||
| 638 | bool isFirstFlingScrollVelocity_ = true; | 638 | bool isFirstFlingScrollVelocity_ = true; |
| 639 | WebLayoutMode layoutMode_ = WebLayoutMode::NONE; | 639 | WebLayoutMode layoutMode_ = WebLayoutMode::NONE; |
| 640 | bool scrollState_ = false; | 640 | bool scrollState_ = false; |
| 641 | - NestedScrollMode nestedScrollMode_ = NestedScrollMode::SELF_FIRST; | 641 | + NestedScrollMode nestedScrollForwardMode_ = NestedScrollMode::SELF_FIRST; |
| 642 | + NestedScrollMode nestedScrollBackwardMode_ = NestedScrollMode::SELF_FIRST; | ||
| 642 | Axis axis_ = Axis::FREE; | 643 | Axis axis_ = Axis::FREE; |
| 643 | int32_t rootLayerWidth_ = 0; | 644 | int32_t rootLayerWidth_ = 0; |
| 644 | int32_t rootLayerHeight_ = 0; | 645 | int32_t rootLayerHeight_ = 0; |
1