aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-09-13 23:38:16 +0800
committer杨宇千 <crupest@outlook.com>2019-09-13 23:38:16 +0800
commit401ca68f7d9d62d195c558edfeda4ece985805e1 (patch)
treec31d89661825a08441fff2673b065d42c423c95c /src
parente3423168a298139051e6bc8b9bacf8b7d594c94e (diff)
downloadcru-401ca68f7d9d62d195c558edfeda4ece985805e1.tar.gz
cru-401ca68f7d9d62d195c558edfeda4ece985805e1.tar.bz2
cru-401ca68f7d9d62d195c558edfeda4ece985805e1.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/ui/routed_event_dispatch.hpp41
-rw-r--r--src/ui/window.cpp22
2 files changed, 39 insertions, 24 deletions
diff --git a/src/ui/routed_event_dispatch.hpp b/src/ui/routed_event_dispatch.hpp
index b032c0a3..a5270575 100644
--- a/src/ui/routed_event_dispatch.hpp
+++ b/src/ui/routed_event_dispatch.hpp
@@ -24,13 +24,21 @@ void DispatchEvent(const std::wstring_view& event_name,
Control* const original_sender,
event::RoutedEvent<EventArgs>* (Control::*event_ptr)(),
Control* const last_receiver, Args&&... args) {
- if (original_sender == last_receiver) {
#ifdef CRU_DEBUG
- log::Debug(
- L"Routed event {} no need to dispatch (original_sender == "
- L"last_receiver). Original sender is {}.",
- event_name, original_sender->GetControlType());
+ bool do_log = true;
+ if (event_name == L"MouseMove") do_log = false;
#endif
+
+ if (original_sender == last_receiver) {
+ /*
+ #ifdef CRU_DEBUG
+ if (do_log)
+ log::Debug(
+ L"Routed event {} no need to dispatch (original_sender == "
+ L"last_receiver). Original sender is {}.",
+ event_name, original_sender->GetControlType());
+ #endif
+ */
return;
}
@@ -43,7 +51,7 @@ void DispatchEvent(const std::wstring_view& event_name,
}
#ifdef CRU_DEBUG
- {
+ if (do_log) {
std::wstring log = L"Dispatch routed event ";
log += event_name;
log += L". Path (parent first): ";
@@ -75,10 +83,11 @@ void DispatchEvent(const std::wstring_view& event_name,
if (event_args.IsHandled()) {
handled = true;
#ifdef CRU_DEBUG
- log::Debug(
- L"Routed event is short-circuit in TUNNEL at {}-st control (count "
- L"from parent).",
- count);
+ if (do_log)
+ log::Debug(
+ L"Routed event is short-circuit in TUNNEL at {}-st control (count "
+ L"from parent).",
+ count);
#endif
break;
}
@@ -95,10 +104,12 @@ void DispatchEvent(const std::wstring_view& event_name,
->Raise(event_args);
if (event_args.IsHandled()) {
#ifdef CRU_DEBUG
- log::Debug(
- L"Routed event is short-circuit in BUBBLE at {}-st control (count "
- L"from parent).",
- count);
+ if (do_log)
+ log::Debug(
+ L"Routed event is short-circuit in BUBBLE at {}-st control "
+ L"(count "
+ L"from parent).",
+ count);
#endif
break;
}
@@ -113,7 +124,7 @@ void DispatchEvent(const std::wstring_view& event_name,
}
#ifdef CRU_DEBUG
- log::Debug(L"Routed event dispatch finished.");
+ if (do_log) log::Debug(L"Routed event dispatch finished.");
#endif
}
} // namespace cru::ui
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index 834b924c..af95c3c6 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -232,15 +232,19 @@ void Window::OnNativeMouseEnterLeave(bool enter) {
void Window::OnNativeMouseMove(const Point& point) {
// Find the first control that hit test succeed.
- const auto new_control_mouse_hover = HitTest(point);
- const auto old_control_mouse_hover = mouse_hover_control_;
- mouse_hover_control_ = new_control_mouse_hover;
+ const auto new_mouse_hover_control = HitTest(point);
+ const auto old_mouse_hover_control = mouse_hover_control_;
+ mouse_hover_control_ = new_mouse_hover_control;
if (mouse_captured_control_) {
- DispatchMouseHoverControlChangeEvent(
- mouse_captured_control_, new_control_mouse_hover, point, false, true);
- DispatchMouseHoverControlChangeEvent(
- old_control_mouse_hover, mouse_captured_control_, point, true, false);
+ const auto n = FindLowestCommonAncestor(new_mouse_hover_control, mouse_captured_control_);
+ const auto o = FindLowestCommonAncestor(old_mouse_hover_control, mouse_captured_control_);
+ bool a = IsAncestor(o, n);
+ if (a) {
+ DispatchEvent(event_names::MouseLeave, o, &Control::MouseLeaveEvent, n);
+ } else {
+ DispatchEvent(event_names::MouseEnter, n, &Control::MouseEnterEvent, o, point);
+ }
DispatchEvent(event_names::MouseMove, mouse_captured_control_,
&Control::MouseMoveEvent, nullptr, point);
UpdateCursor();
@@ -248,8 +252,8 @@ void Window::OnNativeMouseMove(const Point& point) {
}
DispatchMouseHoverControlChangeEvent(
- old_control_mouse_hover, new_control_mouse_hover, point, false, false);
- DispatchEvent(event_names::MouseMove, new_control_mouse_hover,
+ old_mouse_hover_control, new_mouse_hover_control, point, false, false);
+ DispatchEvent(event_names::MouseMove, new_mouse_hover_control,
&Control::MouseMoveEvent, nullptr, point);
UpdateCursor();
}