Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/renderer/dom/element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ void Element::ResetAttribute(const base::String& key) {
if (auto fragment = fragment_impl()) {
if (name == PlatformEventPropName::kEventThrough ||
name == PlatformEventPropName::kEventThroughActiveRegions ||
name == PlatformEventPropName::kEventsPassThrough) {
name == PlatformEventPropName::kEventsPassThrough ||
name == PlatformEventPropName::kIgnoreFocus) {
fragment->SetEventProp(name, lepus::Value());
} else {
fragment->SetEventProp(name, lepus::Value(0));
Expand Down
7 changes: 7 additions & 0 deletions core/renderer/dom/fragment/event/platform_event_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ enum class PlatformEventPropName : int32_t {
kEventThrough = 16,
kEventThroughActiveRegions = 17,
kEventsPassThrough = 18,
kIgnoreFocus = 19,
};

inline PlatformEventPropName PlatformEventPropNameFromString(
Expand Down Expand Up @@ -250,6 +251,9 @@ inline PlatformEventPropName PlatformEventPropNameFromString(
if (name == "events-pass-through") {
return PlatformEventPropName::kEventsPassThrough;
}
if (name == "ignore-focus") {
return PlatformEventPropName::kIgnoreFocus;
}
return PlatformEventPropName::kUnknown;
}

Expand Down Expand Up @@ -312,6 +316,9 @@ inline std::string_view PlatformEventPropNameToString(
if (name == PlatformEventPropName::kEventsPassThrough) {
return "events-pass-through";
}
if (name == PlatformEventPropName::kIgnoreFocus) {
return "ignore-focus";
}
return "";
}

Expand Down
63 changes: 15 additions & 48 deletions core/renderer/dom/fragment/event/platform_event_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ bool PlatformEventHandler::OnInputEvent(
fml::RefPtr<PlatformEventTarget> target_tree, int int_event_data[],
float float_event_data[]) {
target_tree_ = target_tree;
event_handler_state_ = kStateNone;
// int_event_data: [event_type, action_type, event_source, pointer_count, ...]
int event_type = int_event_data[0];
switch (event_type) {
Expand Down Expand Up @@ -85,20 +84,18 @@ bool PlatformEventHandler::OnInputEvent(
}
if (EventThrough()) {
LOGI("PlatformEventHandler::OnInputEvent EventThrough")
event_handler_state_ = kStateEventThrough;
return false;
}

// TODO(hexionghui): forward event to gesture.

event_handler_state_ = kStateNone;
return true;
}

void PlatformEventHandler::OnTap() {
float root_point[2] = {first_pointer_down_point_[0],
first_pointer_down_point_[1]};
if (!first_pointer_moved_ && CanRespondTap(first_target_)) {
if (CanRespondFocus()) {
DispatchGestureEvent(EVENT_TAP, root_point);
}
auto click_target =
Expand Down Expand Up @@ -156,22 +153,6 @@ void PlatformEventHandler::DispatchPointerEvent(
platform_ref_->GetEventEmitter()->SendEvent(first_target_->Sign(), event);
}

void PlatformEventHandler::OnGestureRecognized(int sign) {
gesture_recognized_target_set_.insert(sign);
}

void PlatformEventHandler::SetFocusedTarget(
fml::RefPtr<PlatformEventTarget> focused_target) {
focused_target_ = focused_target;
}

void PlatformEventHandler::UnsetFocusedTarget(
fml::RefPtr<PlatformEventTarget> focused_target) {
if (focused_target_ == focused_target) {
focused_target_ = nullptr;
}
}

bool PlatformEventHandler::EventThrough() {
if (!first_target_) {
return false;
Expand All @@ -182,8 +163,6 @@ bool PlatformEventHandler::EventThrough() {
return first_target_->EventThrough(target_point);
}

int PlatformEventHandler::EventHandlerState() { return event_handler_state_; }

void PlatformEventHandler::SetTapSlop(const std::string& tap_slop) {}

void PlatformEventHandler::SetLongPressDuration(int32_t long_press_duration) {}
Expand All @@ -205,8 +184,14 @@ void PlatformEventHandler::InitPointerEnv(PlatformPointerEvent& event) {
(hit_target ? std::to_string(hit_target->Sign()) : "null"))
float down_point[2] = {pointer_x, pointer_y};
if (pointer_id == 0) {
ResetFocusInfo();
first_target_ = hit_target;
memcpy(first_pointer_down_point_, down_point, sizeof(float) * 2);
if (hit_target != nullptr) {
hit_target_sign_ = hit_target->Sign();
renderer_host_sign_ = hit_target->RendererHostSign();
ignore_focus_ = hit_target->IgnoreFocus();
}
}
target_pointer_map_.insert_or_assign(
pointer_id, PlatformEventTargetDetail(hit_target, down_point));
Expand Down Expand Up @@ -315,7 +300,6 @@ void PlatformEventHandler::OnPointerDown(PlatformPointerEvent& event) {
int num = event.PointerCount();
for (int i = 0; i < num; ++i) {
if (event.PointerID()[i] == 0) {
gesture_recognized_target_set_.clear();
event_target_chain_.clear();
first_pointer_moved_ = false;
first_pointer_outside_ = false;
Expand Down Expand Up @@ -383,7 +367,6 @@ void PlatformEventHandler::OnPointerUp(PlatformPointerEvent& event) {
for (int i = 0; i < num; ++i) {
if (event.PointerID()[i] == 0) {
ResetClickEnv();
UpdateFocusedTarget();
DeactivatePseudoStatus(LynxPseudoStatus::kAll);
break;
}
Expand All @@ -396,7 +379,6 @@ void PlatformEventHandler::OnPointerCancel(PlatformPointerEvent& event) {
if (event.PointerID()[i] == 0) {
ResetClickEnv();
scroll_offset_for_tap_.clear();
UpdateFocusedTarget();
DeactivatePseudoStatus(LynxPseudoStatus::kAll);
break;
}
Expand Down Expand Up @@ -450,17 +432,14 @@ fml::RefPtr<PlatformEventTarget> PlatformEventHandler::FindTarget(
return target_tree_->HitTest(point);
}

void PlatformEventHandler::UpdateFocusedTarget() {
if (first_target_ && !first_target_->IgnoreFocus()) {
if (focused_target_) {
if (focused_target_ != first_target_) {
focused_target_->OnFocusChange(false, first_target_->Focusable());
}
}
first_target_->OnFocusChange(
true, focused_target_ && focused_target_->Focusable());
focused_target_ = first_target_;
}
void PlatformEventHandler::ResetFocusInfo() {
hit_target_sign_ = -1;
renderer_host_sign_ = -1;
ignore_focus_ = false;
}

bool PlatformEventHandler::CanRespondFocus() {
return !first_pointer_moved_ && CanRespondTap(first_target_);
}

bool PlatformEventHandler::CanRespondTap(
Expand All @@ -471,18 +450,6 @@ bool PlatformEventHandler::CanRespondTap(
if (HasScrollContainerScrolledForTap()) {
return false;
}
if (gesture_recognized_target_set_.empty()) {
return true;
}

while (target && target->ParentTarget() != target) {
if (gesture_recognized_target_set_.find(target->Sign()) !=
gesture_recognized_target_set_.end()) {
// it means that a node in the event response chain is scrolling.
return false;
}
target = target->ParentTarget();
}
return true;
}

Expand Down
23 changes: 8 additions & 15 deletions core/renderer/dom/fragment/event/platform_event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <limits>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "core/renderer/dom/fragment/event/platform_event_target.h"
Expand All @@ -24,11 +23,6 @@ class NativePaintingCtxPlatformRef;

class PlatformEventHandler {
public:
enum EventHandlerState {
kStateNone = 0,
kStateEventThrough = 1,
};

class PlatformEventTargetDetail {
public:
PlatformEventTargetDetail(fml::RefPtr<PlatformEventTarget> target,
Expand Down Expand Up @@ -57,12 +51,11 @@ class PlatformEventHandler {
void DispatchPointerEvent(const std::string& name,
const lepus::Value& target_pointer_map);

void OnGestureRecognized(int sign);
void SetFocusedTarget(fml::RefPtr<PlatformEventTarget> focused_target);
void UnsetFocusedTarget(fml::RefPtr<PlatformEventTarget> focused_target);

bool EventThrough();
int EventHandlerState();
int32_t HitTargetSign() const { return hit_target_sign_; }
int32_t RendererHostSign() const { return renderer_host_sign_; }
bool IgnoreFocus() const { return ignore_focus_; }
bool CanRespondFocus();

void SetTapSlop(const std::string& tap_slop);
void SetLongPressDuration(int32_t long_press_duration);
Expand All @@ -88,7 +81,7 @@ class PlatformEventHandler {

void DispatchGestureEvent(const std::string& name, float root_point[2]);
fml::RefPtr<PlatformEventTarget> FindTarget(float pointer_x, float pointer_y);
void UpdateFocusedTarget();
void ResetFocusInfo();
bool CanRespondTap(fml::RefPtr<PlatformEventTarget> target);
void ActivePseudoStatus();
void DeactivatePseudoStatus(LynxPseudoStatus status);
Expand All @@ -102,15 +95,15 @@ class PlatformEventHandler {
NativePaintingCtxPlatformRef* platform_ref_{nullptr};

// state
int event_handler_state_{kStateNone};
fml::RefPtr<PlatformEventTarget> target_tree_{nullptr};
fml::RefPtr<PlatformEventTarget> first_target_{nullptr};
fml::RefPtr<PlatformEventTarget> focused_target_{nullptr};
std::vector<fml::RefPtr<PlatformEventTarget>> event_target_chain_;
std::deque<fml::RefPtr<PlatformEventTarget>> click_target_chain_;
std::unordered_map<int, PlatformEventTargetDetail> target_pointer_map_;
std::unordered_set<int> gesture_recognized_target_set_;
std::unordered_map<int32_t, std::array<float, 2>> scroll_offset_for_tap_;
int32_t hit_target_sign_{-1};
int32_t renderer_host_sign_{-1};
bool ignore_focus_{false};
bool has_pointer_moved_{false};
bool first_pointer_moved_{false};
bool first_pointer_outside_{false};
Expand Down
26 changes: 20 additions & 6 deletions core/renderer/dom/fragment/event/platform_event_target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ void PlatformEventTarget::OffResponseChain() {}

bool PlatformEventTarget::IsOnResponseChain() const { return false; }

void PlatformEventTarget::OnFocusChange(bool has_focus,
bool is_focus_transition) {}

bool PlatformEventTarget::Focusable() const { return true; }

void PlatformEventTarget::OnPseudoStatusChanged(
LynxPseudoStatus pre_status, LynxPseudoStatus current_status) {}

Expand Down Expand Up @@ -337,7 +332,26 @@ float PlatformEventTarget::ConvertEventThroughSizeValue(
return value.value;
}

bool PlatformEventTarget::IgnoreFocus() const { return false; }
bool PlatformEventTarget::IgnoreFocus() const {
if (ignore_focus_ == LynxEventPropStatus::kEnable) {
return true;
}
if (ignore_focus_ == LynxEventPropStatus::kDisable) {
return false;
}

// An event root does not inherit ignore-focus from another event root. A
// descendant may only inherit from a parent in the same event target tree.
if (IsRoot()) {
return false;
}
auto parent = ParentTarget();
if (parent == nullptr || parent.get() == this ||
parent->RootId() != RootId()) {
return false;
}
return parent->IgnoreFocus();
}

LynxPointerEventsValue PlatformEventTarget::PointerEvents() const {
return LynxPointerEventsValue::kAuto;
Expand Down
7 changes: 5 additions & 2 deletions core/renderer/dom/fragment/event/platform_event_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class PlatformEventTarget

int32_t RootId() const { return root_id_; }
int32_t Sign() const { return sign_; }
int32_t RendererHostSign() const { return renderer_host_sign_; }
float Left() const { return left_; }
float Top() const { return top_; }
float Width() const { return width_; }
Expand Down Expand Up @@ -183,8 +184,6 @@ class PlatformEventTarget
void OffResponseChain();
bool IsOnResponseChain() const;

void OnFocusChange(bool has_focus, bool is_focus_transition);
bool Focusable() const;
void OnPseudoStatusChanged(LynxPseudoStatus pre_status,
LynxPseudoStatus current_status);
LynxPseudoStatus GetPseudoStatus() const;
Expand Down Expand Up @@ -241,6 +240,7 @@ class PlatformEventTarget
void SetPlatformRendererType(PlatformRendererType type) {
platform_renderer_type_ = type;
}
void SetRendererHostSign(int32_t sign) { renderer_host_sign_ = sign; }
void SetScrollContainer(bool is_scroll_container) {
is_scroll_container_ = is_scroll_container;
}
Expand All @@ -258,6 +258,7 @@ class PlatformEventTarget
void SetEventsPassThrough(LynxEventPropStatus value) {
events_pass_through_ = value;
}
void SetIgnoreFocus(LynxEventPropStatus value) { ignore_focus_ = value; }

private:
void UpdateScrollOffsetIfNeeded();
Expand All @@ -275,6 +276,7 @@ class PlatformEventTarget
// target props
int32_t root_id_;
int32_t sign_;
int32_t renderer_host_sign_{-1};
float left_{0.f};
float top_{0.f};
float width_{0.f};
Expand Down Expand Up @@ -305,6 +307,7 @@ class PlatformEventTarget
LynxEventPropStatus enable_exposure_ui_clip_{LynxEventPropStatus::kUndefined};
LynxEventPropStatus event_through_{LynxEventPropStatus::kUndefined};
LynxEventPropStatus events_pass_through_{LynxEventPropStatus::kUndefined};
LynxEventPropStatus ignore_focus_{LynxEventPropStatus::kUndefined};
std::vector<EventThroughRegion> event_through_active_regions_;
std::string id_selector_;
std::string exposure_id_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void SetEventThrough(PlatformEventTarget* target, const lepus::Value& value) {
target->SetEventThrough(EventPropValueToStatus(value));
}

void SetIgnoreFocus(PlatformEventTarget* target, const lepus::Value& value) {
target->SetIgnoreFocus(EventPropValueToStatus(value));
}

bool ParseEventThroughSizeValue(
const lepus::Value& value,
PlatformEventTarget::EventThroughSizeValue* result) {
Expand Down Expand Up @@ -297,6 +301,7 @@ GetEventPropSetterMap() {
{PlatformEventPropName::kEventThroughActiveRegions,
&SetEventThroughActiveRegions},
{PlatformEventPropName::kEventsPassThrough, &SetEventsPassThrough},
{PlatformEventPropName::kIgnoreFocus, &SetIgnoreFocus},
};
return map;
}
Expand Down Expand Up @@ -536,6 +541,7 @@ PlatformEventTargetHelper::ReconstructEventTargetTreeRecursively(
const auto type = static_cast<PlatformRendererType>(begin.type);
auto event_target = fml::MakeRefCounted<PlatformEventTarget>(
this, tree_root_id, sign, begin.x, begin.y, begin.w, begin.h);
event_target->SetRendererHostSign(page_renderer->GetId());
event_target->SetPlatformRendererType(type);
event_target->SetScrollContainer(IsScrollContainer(type, sign));
event_target->SetOverflow(begin.overflow_x != 0, begin.overflow_y != 0);
Expand Down
Loading
Loading