Diff
diff --git a/events/main.go b/events/main.go
index 2181128..93b9872 100644
--- a/events/main.go
+++ b/events/main.go
@@ -8,2 +7,0 @@ import (
- "sort"
- "strconv"
@@ -11 +8,0 @@ import (
- "unicode"
@@ -24,5 +21,5 @@ type Monitor struct {
- State *map[string]element.State
- Adapter *adapter.Adapter
- EventMap map[string]element.Event
- CSS *cstyle.CSS
- Focus Focus
+ State *map[string]element.State
+ Adapter *adapter.Adapter
+ History *map[string]element.EventList
+ CSS *cstyle.CSS
+ Focus Focus
@@ -34,2 +31,2 @@ type Focus struct {
- Nodes []string
- SoftFocused string
+ Nodes []*element.Node
+ SoftFocused *element.Node
@@ -39,103 +36 @@ type Focus struct {
-func (m *Monitor) RunEvents(n *element.Node) bool {
- var scrolled bool
- for _, v := range n.Children {
- scrolled = m.RunEvents(v)
- }
-
- evt := m.EventMap[n.Properties.Id]
- evt.Target = n
-
- if scrolled {
- evt.Scroll = 0
- m.EventMap[n.Properties.Id] = evt
- }
- eventListeners := []string{}
-
- if evt.MouseDown {
- if n.OnMouseDown != nil {
- n.OnMouseDown(evt)
- }
- eventListeners = append(eventListeners, "mousedown")
- }
-
- if evt.MouseUp {
- if n.OnMouseUp != nil {
- n.OnMouseUp(evt)
- }
- eventListeners = append(eventListeners, "mouseup")
- }
-
- if evt.Click {
- if n.OnClick != nil {
- n.OnClick(evt)
- }
- eventListeners = append(eventListeners, "click")
- }
-
- if evt.ContextMenu {
- if n.OnContextMenu != nil {
- n.OnContextMenu(evt)
- }
- eventListeners = append(eventListeners, "contextmenu")
- }
-
- if evt.MouseEnter {
- if n.OnMouseEnter != nil {
- n.OnMouseEnter(evt)
- }
- eventListeners = append(eventListeners, "mouseenter")
- }
-
- if evt.MouseOver {
- if n.OnMouseOver != nil {
- n.OnMouseOver(evt)
- }
- eventListeners = append(eventListeners, "mouseover")
- }
-
- if evt.MouseLeave {
- if n.OnMouseLeave != nil {
- n.OnMouseLeave(evt)
- }
- eventListeners = append(eventListeners, "mouseleave")
- }
-
- if evt.Hover {
- n.ClassList.Add(":hover")
- } else {
- n.ClassList.Remove(":hover")
- }
-
- if len(m.Focus.Nodes) > 0 && m.Focus.Selected > -1 {
- if m.Focus.Nodes[m.Focus.Selected] == n.Properties.Id {
- n.Focus()
- } else {
- n.Blur()
- }
- } else {
- n.Blur()
- }
-
- if evt.Scroll != 0 {
- styledEl, _ := m.CSS.GetStyles(n)
-
- // !TODO: Add scrolling for dragging over the scroll bar
- if hasAutoOrScroll(styledEl) {
- n.ScrollTop = int(n.ScrollTop + (-evt.Scroll))
- if n.ScrollTop > n.ScrollHeight {
- n.ScrollTop = n.ScrollHeight
- }
-
- if n.ScrollTop <= 0 {
- n.ScrollTop = 0
- }
-
- if n.OnScroll != nil {
- n.OnScroll(evt)
- }
-
- evt.Scroll = 0
- m.EventMap[n.Properties.Id] = evt
- scrolled = true
- }
- }
+func (m *Monitor) RunEvents(n *element.Node) {
@@ -143,8 +37,0 @@ func (m *Monitor) RunEvents(n *element.Node) bool {
- for _, v := range eventListeners {
- if len(n.Properties.EventListeners[v]) > 0 {
- for _, handler := range n.Properties.EventListeners[v] {
- handler(evt)
- }
- }
- }
- return scrolled
@@ -153,4 +40 @@ func (m *Monitor) RunEvents(n *element.Node) bool {
-type fn struct {
- Id string
- TabIndex int
-}
+// It does make sense that events would be attached to the state and not the document (the fake document)
@@ -159,12 +42,0 @@ func (m *Monitor) GetEvents(data *EventData) {
- headElements := []string{
- "head",
- "title", // Defines the title of the document
- "base", // Specifies the base URL for all relative URLs in the document
- "link", // Links to external resources like stylesheets
- "meta", // Provides metadata about the document (e.g., character set, viewport)
- "style", // Embeds internal CSS styles
- "script", // Embeds or references JavaScript code
- "noscript", // Provides alternate content for users without JavaScript
- "template", // Used to define a client-side template
- }
-
@@ -173,20 +45 @@ func (m *Monitor) GetEvents(data *EventData) {
- m.Focus.LastClickWasFocused = false
- // update focesable nodes
- nodes := []fn{}
- for k, self := range s {
- if self.TabIndex > -1 {
- if self.TabIndex == 9999999 {
- // Add the last digits of the properties.id to make the elements sort in order
- numStr := strings.TrimFunc(k, func(r rune) bool {
- return !unicode.IsDigit(r) // Remove non-digit characters
- })
- prid, _ := strconv.Atoi(numStr)
- self.TabIndex += prid
- }
- nodes = append(nodes, fn{Id: k, TabIndex: self.TabIndex})
- }
- }
-
- sort.Slice(nodes, func(i, j int) bool {
- return nodes[i].TabIndex < nodes[j].TabIndex // Ascending order by TabIndex
- })
+ eventMap := map[string][]element.Event{}
@@ -194,14 +47,3 @@ func (m *Monitor) GetEvents(data *EventData) {
- m.Focus.Nodes = []string{}
- for _, v := range nodes {
- good := true
-
- for _, tag := range headElements {
- if len(v.Id) >= len(tag) {
- if v.Id[0:len(tag)] == tag {
- good = false
- }
- }
- }
-
- if good {
- m.Focus.Nodes = append(m.Focus.Nodes, v.Id)
+ for k, self := range s {
+ if data.Click {
+ m.Focus.SoftFocused = nil
@@ -209 +50,0 @@ func (m *Monitor) GetEvents(data *EventData) {
- }
@@ -211,3 +51,0 @@ func (m *Monitor) GetEvents(data *EventData) {
- var softFocus string
-
- for k, self := range s {
@@ -216,2 +54,2 @@ func (m *Monitor) GetEvents(data *EventData) {
- if m.Focus.SoftFocused != "" {
- isFocused = m.Focus.SoftFocused == k
+ if m.Focus.SoftFocused != nil {
+ isFocused = m.Focus.SoftFocused.Properties.Id == k
@@ -219,5 +57 @@ func (m *Monitor) GetEvents(data *EventData) {
- if m.Focus.Selected > -1 {
- isFocused = m.Focus.Nodes[m.Focus.Selected] == k
- } else {
- isFocused = false
- }
+ isFocused = false
@@ -226 +60 @@ func (m *Monitor) GetEvents(data *EventData) {
- evt, ok := m.EventMap[k]
+ evt := element.Event{}
@@ -228,7 +62,2 @@ func (m *Monitor) GetEvents(data *EventData) {
- if !ok {
- evt = element.Event{}
- }
-
- if evt.X != int(data.Position[0]) && evt.Y != int(data.Position[1]) {
- evt.X = int(data.Position[0])
- evt.Y = int(data.Position[1])
+ if eventMap[k] == nil {
+ eventMap[k] = []element.Event{}
@@ -243,10 +71,0 @@ func (m *Monitor) GetEvents(data *EventData) {
- if m.Focus.SoftFocused == k || inside {
- if data.Key == 265 {
- // up
- arrowScroll += 20
- } else if data.Key == 264 {
- // Down
- arrowScroll -= 20
- }
- }
-
@@ -254 +72,0 @@ func (m *Monitor) GetEvents(data *EventData) {
-
@@ -256 +74,9 @@ func (m *Monitor) GetEvents(data *EventData) {
-
+ if m.Focus.SoftFocused != nil {
+ if data.Key == 265 {
+ // up
+ arrowScroll += 20
+ } else if data.Key == 264 {
+ // Down
+ arrowScroll -= 20
+ }
+ }
@@ -277,0 +104,4 @@ func (m *Monitor) GetEvents(data *EventData) {
+ if store > -1 {
+ m.Focus.Nodes[store].Blur()
+ }
+ m.Focus.Nodes[m.Focus.Selected].Focus()
@@ -289 +119,5 @@ func (m *Monitor) GetEvents(data *EventData) {
- evt.Hover = true
+ if evt.AddClasses == nil {
+ evt.AddClasses = []string{}
+ }
+
+ evt.AddClasses = append(evt.AddClasses, ":hover")
@@ -304,76 +137,0 @@ func (m *Monitor) GetEvents(data *EventData) {
- fmt.Println(k, inside, isFocused)
-
- if self.TabIndex > -1 {
- if m.Focus.Selected > -1 {
- if len(m.Focus.Nodes) > 0 && m.Focus.Selected > -1 {
- if m.Focus.Nodes[m.Focus.Selected] != k {
- for i, v := range m.Focus.Nodes {
- if v == k {
- m.Focus.Selected = i
- m.Focus.LastClickWasFocused = true
- break
- }
- }
- } else {
- m.Focus.LastClickWasFocused = true
- }
- } else {
- m.Focus.LastClickWasFocused = true
- }
-
- } else {
- selectedIndex := -1
- for i, v := range m.Focus.Nodes {
- if v == k {
- selectedIndex = i
- }
- }
- if selectedIndex == -1 {
- if self.TabIndex == 9999999 {
- // Add the last digits of the properties.id to make the elements sort in order
- numStr := strings.TrimFunc(k, func(r rune) bool {
- return !unicode.IsDigit(r) // Remove non-digit characters
- })
- prid, _ := strconv.Atoi(numStr)
- self.TabIndex += prid
- }
- nodes = append(nodes, fn{Id: k, TabIndex: self.TabIndex})
- sort.Slice(nodes, func(i, j int) bool {
- return nodes[i].TabIndex < nodes[j].TabIndex // Ascending order by TabIndex
- })
- m.Focus.Nodes = []string{}
- for _, v := range nodes {
- m.Focus.Nodes = append(m.Focus.Nodes, v.Id)
- }
-
- for i, v := range m.Focus.Nodes {
- if v == k {
- selectedIndex = i
- }
- }
- }
-
- m.Focus.Selected = selectedIndex
- m.Focus.LastClickWasFocused = true
- }
-
- } else if m.Focus.Selected > -1 {
- if len(m.Focus.Nodes) > 0 && m.Focus.Selected > -1 {
- if m.Focus.Nodes[m.Focus.Selected] != k && !m.Focus.LastClickWasFocused {
- m.Focus.Selected = -1
- }
- }
- }
- if inside {
- if softFocus == "" {
- softFocus = k
- } else {
- if s[softFocus].Z < s[k].Z {
- softFocus = k
- } else if s[softFocus].Z == s[k].Z {
- if extractNumber(k) < extractNumber(softFocus) {
- softFocus = k
- }
- }
- }
- }
@@ -380,0 +139,56 @@ func (m *Monitor) GetEvents(data *EventData) {
+ // if n.TabIndex > -1 {
+ // if m.Focus.Selected > -1 {
+ // if m.Focus.Nodes[m.Focus.Selected].Properties.Id != k {
+ // m.Focus.Nodes[m.Focus.Selected].Blur()
+ // for i, v := range m.Focus.Nodes {
+ // if v.Properties.Id == k {
+ // m.Focus.Selected = i
+ // m.Focus.LastClickWasFocused = true
+ // break
+ // }
+ // }
+ // } else {
+ // m.Focus.LastClickWasFocused = true
+ // }
+ // } else {
+ // selectedIndex := -1
+ // for i, v := range m.Focus.Nodes {
+ // if v.Properties.Id == k {
+ // selectedIndex = i
+ // }
+ // }
+ // if selectedIndex == -1 {
+ // if n.TabIndex == 9999999 {
+ // // Add the last digits of the properties.id to make the elements sort in order
+ // numStr := strings.TrimFunc(k, func(r rune) bool {
+ // return !unicode.IsDigit(r) // Remove non-digit characters
+ // })
+ // prid, _ := strconv.Atoi(numStr)
+ // n.TabIndex += prid
+ // }
+ // m.Focus.Nodes = append([]*element.Node{n}, m.Focus.Nodes...)
+ // sort.Slice(m.Focus.Nodes, func(i, j int) bool {
+ // return m.Focus.Nodes[i].TabIndex < m.Focus.Nodes[j].TabIndex // Ascending order by TabIndex
+ // })
+ // for i, v := range m.Focus.Nodes {
+ // if v.Properties.Id == k {
+ // selectedIndex = i
+ // }
+ // }
+ // }
+
+ // m.Focus.Selected = selectedIndex
+ // m.Focus.LastClickWasFocused = true
+ // }
+
+ // } else if m.Focus.Selected > -1 {
+ // if m.Focus.Nodes[m.Focus.Selected].Properties.Id != k && !m.Focus.LastClickWasFocused {
+ // m.Focus.Nodes[m.Focus.Selected].Blur()
+ // m.Focus.Selected = -1
+ // }
+ // }
+
+ // Regardless set soft focus to trigger events to the selected element: when non is set default body???
+ // if m.Focus.SoftFocused == nil {
+ // m.Focus.SoftFocused = n
+ // }
@@ -382 +195,0 @@ func (m *Monitor) GetEvents(data *EventData) {
- // Regardless set soft focus to trigger events to the selected element: when non is set default body???
@@ -388,5 +201,28 @@ func (m *Monitor) GetEvents(data *EventData) {
- if (data.Scroll != 0 && (inside)) || arrowScroll != 0 {
- // !TODO: for now just emit a event, will have to add el.scrollX
- evt.Scroll = data.Scroll + arrowScroll
- arrowScroll = 0
- }
+ // el.ScrollY = 0
+ // if (data.Scroll != 0 && (inside)) || arrowScroll != 0 {
+ // // !TODO: for now just emit a event, will have to add el.scrollX
+ // data.Scroll += arrowScroll
+ // styledEl, _ := m.CSS.GetStyles(n)
+
+ // // !TODO: Add scrolling for dragging over the scroll bar
+ // // + the dragging part will be hard as events has no context of the scrollbars
+
+ // if hasAutoOrScroll(styledEl) {
+ // n.ScrollTop = int(n.ScrollTop + (-data.Scroll))
+ // if n.ScrollTop > n.ScrollHeight {
+ // n.ScrollTop = n.ScrollHeight
+ // }
+
+ // if n.ScrollTop <= 0 {
+ // n.ScrollTop = 0
+ // }
+
+ // if n.OnScroll != nil {
+ // n.OnScroll(evt)
+ // }
+
+ // data.Scroll = 0
+ // eventList = append(eventList, "scroll")
+ // }
+
+ // }
@@ -400,4 +236,4 @@ func (m *Monitor) GetEvents(data *EventData) {
- m.Adapter.DispatchEvent(element.Event{
- Name: "cursor",
- Data: self.Cursor,
- })
+ // m.Adapter.DispatchEvent(element.Event{
+ // Name: "cursor",
+ // Data: self.Cursor,
+ // })
@@ -405,0 +242,5 @@ func (m *Monitor) GetEvents(data *EventData) {
+ if evt.X != int(data.Position[0]) && evt.Y != int(data.Position[1]) {
+ evt.X = int(data.Position[0])
+ evt.Y = int(data.Position[1])
+
+ }
@@ -408 +249,5 @@ func (m *Monitor) GetEvents(data *EventData) {
- evt.Hover = false
+ if evt.RemoveClasses == nil {
+ evt.RemoveClasses = []string{}
+ }
+
+ evt.RemoveClasses = append(evt.RemoveClasses, ":hover")
@@ -418 +263 @@ func (m *Monitor) GetEvents(data *EventData) {
- m.EventMap[k] = evt
+ eventMap[k] = append(eventMap[k], evt)
@@ -421,4 +266 @@ func (m *Monitor) GetEvents(data *EventData) {
- if softFocus != "" {
- // fmt.Println(softFocus)
- m.Focus.SoftFocused = softFocus
- }
+ fmt.Println(eventMap["ROOT"])
@@ -486,13 +327,0 @@ func hasAutoOrScroll(styledEl map[string]string) bool {
-func extractNumber(input string) int {
- var numStr string
- for _, char := range input {
- if unicode.IsDigit(char) {
- numStr += string(char)
- }
- }
- if numStr == "" {
- return 0
- }
- n, _ := strconv.Atoi(numStr)
- return n
-}