// MouseEnter is an event fired when a pointing device is moved onto the
// element that has the listener attached.
//
// https://developer.mozilla.org/docs/Web/Events/mouseenter
969396
func MouseEnter(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "mouseenter", Listener: listener}
}
514319
func PointerOut(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "pointerout", Listener: listener}
}
345441
func (e *TextEdit) OnKeyEvent(ev KeyEvent) {
	if !e.IsFocused() {
		return
	}

	screenWidth := e.Size().X
	e.text.SetMaxWidth(screenWidth)

	if ev.Key != KeyRune {
		switch ev.Key {
		case KeyEnter:
			e.text.WriteRune('\n')
		case KeyBackspace:
			fallthrough
		case KeyBackspace2:
			e.text.Backspace()
			if e.offset > 0 && !e.isTextRemaining() {
				e.offset--
			}
			if e.onTextChange != nil {
				e.onTextChange(e)
			}
		case KeyDelete, KeyCtrlD:
			e.text.Delete()
			if e.onTextChange != nil {
				e.onTextChange(e)
			}
		case KeyLeft, KeyCtrlB:
			e.text.MoveBackward()
			if e.offset > 0 {
				e.offset--
			}
		case KeyRight, KeyCtrlF:
			e.text.MoveForward()

			isCursorTooFar := e.text.CursorPos().X >= screenWidth
			isTextLeft := (e.text.Width() - e.offset) > (screenWidth - 1)

			if isCursorTooFar && isTextLeft {
				e.offset++
			}
		case KeyHome, KeyCtrlA:
			e.text.MoveToLineStart()
			e.offset = 0
		case KeyEnd, KeyCtrlE:
			e.text.MoveToLineEnd()
			left := e.text.Width() - (screenWidth - 1)
			if left >= 0 {
				e.offset = left
			}
		case KeyCtrlK:
			e.text.Kill()
		}
		return
	}

	e.text.WriteRune(ev.Rune)
	if e.text.CursorPos().X >= screenWidth {
		e.offset++
	}
	if e.onTextChange != nil {
		e.onTextChange(e)
	}
}
277317
func (e *Element) Click() error {
	x, y, err := e.getCenter()
	if err != nil {
		return err
	}

	// click the centroid of the element.
	return e.tab.Click(float64(x), float64(y))
}
746806
func (m *MouseSystem) AddByInterface(i ecs.Identifier) {
	o, _ := i.(Mouseable)
	m.Add(o.GetBasicEntity(), o.GetMouseComponent(), o.GetSpaceComponent(), o.GetRenderComponent())
}
1229957
func (e *Element) MouseOver() error {
	x, y, err := e.getCenter()
	if err != nil {
		return err
	}
	return e.tab.MoveMouse(float64(x), float64(y))
}
629224
func DeviceLight(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "devicelight", Listener: listener}
}
738987
func DragLeave(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "dragleave", Listener: listener}
}
402252
func (f *Form) Focus(delegate func(p Primitive)) {
	if len(f.items)+len(f.buttons) == 0 {
		f.hasFocus = true
		return
	}
	f.hasFocus = false

	// Hand on the focus to one of our child elements.
	if f.focusedElement < 0 || f.focusedElement >= len(f.items)+len(f.buttons) {
		f.focusedElement = 0
	}
	handler := func(key tcell.Key) {
		switch key {
		case tcell.KeyTab, tcell.KeyEnter:
			f.focusedElement++
			f.Focus(delegate)
		case tcell.KeyBacktab:
			f.focusedElement--
			if f.focusedElement < 0 {
				f.focusedElement = len(f.items) + len(f.buttons) - 1
			}
			f.Focus(delegate)
		case tcell.KeyEscape:
			if f.cancel != nil {
				f.cancel()
			} else {
				f.focusedElement = 0
				f.Focus(delegate)
			}
		}
	}

	if f.focusedElement < len(f.items) {
		// We're selecting an item.
		item := f.items[f.focusedElement]
		item.SetFinishedFunc(handler)
		delegate(item)
	} else {
		// We're selecting a button.
		button := f.buttons[f.focusedElement-len(f.items)]
		button.SetBlurFunc(handler)
		delegate(button)
	}
}
190344
func (e *Element) Focus() error {
	e.lock.RLock()
	defer e.lock.RUnlock()

	params := &gcdapi.DOMFocusParams{
		NodeId: e.id,
	}
	_, err := e.tab.DOM.FocusWithParams(params)
	return err
}
610868
func KeyDown(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "keydown", Listener: listener}
}
158045
func PointerOver(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "pointerover", Listener: listener}
}
593806
func DragOver(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "dragover", Listener: listener}
}
505232
func (c *DOMDebugger) RemoveInstrumentationBreakpoint(eventName string) (*gcdmessage.ChromeResponse, error) {
	var v DOMDebuggerRemoveInstrumentationBreakpointParams
	v.EventName = eventName
	return c.RemoveInstrumentationBreakpointWithParams(&v)
}
59595
func (b *Button) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) {
	return b.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) {
		// Process key event.
		switch key := event.Key(); key {
		case tcell.KeyEnter: // Selected.
			if b.selected != nil {
				b.selected()
			}
		case tcell.KeyBacktab, tcell.KeyTab, tcell.KeyEscape: // Leave. No action.
			if b.blur != nil {
				b.blur(key)
			}
		}
	})
}
897554
func (b *BoxLayout) HandleEvent(ev tcell.Event) bool {
	switch ev.(type) {
	case *EventWidgetContent:
		// This can only have come from one of our children.
		b.changed = true
		b.PostEventWidgetContent(b)
		return true
	}
	for _, c := range b.cells {
		if c.widget.HandleEvent(ev) {
			return true
		}
	}
	return false
}
540716
func Click(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "click", Listener: listener}
}