click_diagnostics.go RawHistoryFolder
1package cef
2
3import (
4 "fmt"
5
6 "github.com/bnema/dumber/internal/logging"
7 cef2gtk "github.com/bnema/purego-cef2gtk"
8 "github.com/rs/zerolog"
9)
10
11func clickDiagnosticPhaseName(phase cef2gtk.ClickDiagnosticPhase) string {
12 switch phase {
13 case cef2gtk.ClickDiagnosticPressed:
14 return "pressed"
15 case cef2gtk.ClickDiagnosticReleased:
16 return "released"
17 case cef2gtk.ClickDiagnosticCancelled:
18 return "canceled"
19 case cef2gtk.ClickDiagnosticForwarded:
20 return "forwarded"
21 case cef2gtk.ClickDiagnosticConsumed:
22 return "consumed"
23 case cef2gtk.ClickDiagnosticDropped:
24 return "dropped"
25 default:
26 return fmt.Sprintf("unknown(%d)", phase)
27 }
28}
29
30func clickDropReasonName(reason cef2gtk.ClickDropReason) string {
31 switch reason {
32 case cef2gtk.ClickDropReasonNone:
33 return "none"
34 case cef2gtk.ClickDropReasonMissingHost:
35 return "missing_host"
36 case cef2gtk.ClickDropReasonDetached:
37 return "detached"
38 case cef2gtk.ClickDropReasonMissingInputState:
39 return "missing_input_state"
40 default:
41 return fmt.Sprintf("unknown(%d)", reason)
42 }
43}
44
45func clickButtonName(button uint) string {
46 switch button {
47 case 1:
48 return "primary"
49 case 2:
50 return "middle"
51 case 3:
52 return "secondary"
53 default:
54 return "other"
55 }
56}
57
58func (wv *WebView) logClickDiagnostic(event cef2gtk.ClickDiagnosticEvent) {
59 if wv == nil || wv.ctx == nil {
60 return
61 }
62 wv.mu.RLock()
63 browserID := int32(0)
64 if wv.browser != nil {
65 browserID = wv.browser.GetIdentifier()
66 }
67 inputAttached := wv.inputAttached
68 visibilityKnown := wv.effectiveVisibilityKnown
69 visible := wv.effectiveVisible
70 bridge := wv.viewBridge
71 bridgePresent := bridge != nil
72 wv.mu.RUnlock()
73 bridgeFocused := bridgePresent && bridge.HasFocus()
74
75 logger := logging.FromContext(wv.ctx)
76 var logEvent *zerolog.Event
77 if event.Phase == cef2gtk.ClickDiagnosticDropped || event.Phase == cef2gtk.ClickDiagnosticCancelled {
78 logEvent = logger.Warn()
79 } else {
80 logEvent = logger.Debug()
81 }
82 logEvent.
83 Uint64("webview_id", uint64(wv.id)).
84 Int32("browser_id", browserID).
85 Str("phase", clickDiagnosticPhaseName(event.Phase)).
86 Uint("button", event.Button).
87 Str("button_type", clickButtonName(event.Button)).
88 Int("click_count", event.ClickCount).
89 Str("drop_reason", clickDropReasonName(event.DropReason)).
90 Bool("input_attached", inputAttached).
91 Bool("effective_visibility_known", visibilityKnown).
92 Bool("effective_visible", visible).
93 Bool("destroyed", wv.destroyed.Load()).
94 Bool("bridge_present", bridgePresent).
95 Bool("bridge_focused", bridgeFocused).
96 Msg("cef: click routing diagnostic")
97}