public void MouseDown(UIMouseEventArgs e, CssBox startAt) { if (!_isBinded) { return; } if (startAt == null) { return; } //---------------------------------------------------- ClearPreviousSelection(); if (_latestMouseDownChain != null) { ReleaseHitChain(_latestMouseDownChain); _latestMouseDownChain = null; } this.lastDomLayoutVersion = this._htmlContainer.LayoutVersion; //---------------------------------------------------- int x = e.X; int y = e.Y; this._mouseDownStartAt = startAt; this._mousedownX = x; this._mousedownY = y; CssBoxHitChain hitChain = GetFreeHitChain(); hitChain.SetRootGlobalPosition(x, y); //1. hittest BoxHitUtils.HitTest(startAt, x, y, hitChain); //2. propagate events SetEventOrigin(e, hitChain); ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) => { portal.PortalMouseDown(e); return(true); }); if (!e.CancelBubbling) { var prevMouseDownElement = this.currentMouseDown; e.CurrentContextElement = this.currentMouseDown = null; //clear ForEachEventListenerBubbleUp(e, hitChain, () => { //TODO: check accept keyboard this.currentMouseDown = e.CurrentContextElement; e.CurrentContextElement.ListenMouseDown(e); if (prevMouseDownElement != null && prevMouseDownElement != currentMouseDown) { prevMouseDownElement.ListenLostMouseFocus(e); } return(e.CancelBubbling); }); } //---------------------------------- //save mousedown hitchain this._latestMouseDownChain = hitChain; }
public void MouseUp(UIMouseEventArgs e, CssBox startAt) { if (!_isBinded) { return; } if (startAt == null) { return; } //---------------------------------------------------- DateTime snapMouseUpTime = DateTime.Now; TimeSpan timediff = snapMouseUpTime - lastimeMouseUp; bool isAlsoDoubleClick = timediff.Milliseconds < DOUBLE_CLICK_SENSE; this.lastimeMouseUp = snapMouseUpTime; //----------------------------------------- CssBoxHitChain hitChain = GetFreeHitChain(); hitChain.SetRootGlobalPosition(e.X, e.Y); //1. prob hit chain only BoxHitUtils.HitTest(startAt, e.X, e.Y, hitChain); SetEventOrigin(e, hitChain); //2. invoke css event and script event ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) => { portal.PortalMouseUp(e); return(true); }); if (!e.CancelBubbling) { ForEachEventListenerBubbleUp(e, hitChain, () => { e.CurrentContextElement.ListenMouseUp(e); return(e.CancelBubbling); }); } if (!e.IsCanceled) { //-------------------- //click or double click //-------------------- if (isAlsoDoubleClick) { ForEachEventListenerBubbleUp(e, hitChain, () => { e.CurrentContextElement.ListenMouseDoubleClick(e); return(e.CancelBubbling); }); } else { ForEachEventListenerBubbleUp(e, hitChain, () => { e.CurrentContextElement.ListenMouseClick(e); return(e.CancelBubbling); }); } } ReleaseHitChain(hitChain); if (this._latestMouseDownChain != null) { this._latestMouseDownChain.Clear(); //Console.WriteLine(dbugNN++); this._latestMouseDownChain = null; } }
public void MouseDown(UIMouseDownEventArgs e, CssBox startAt) { if (!_isBinded) { return; } if (startAt == null) { return; } //---------------------------------------------------- if (!e.Shift) { ClearPreviousSelection(); } if (_latestMouseDownChain != null) { ReleaseHitChain(_latestMouseDownChain); _latestMouseDownChain = null; } _lastDomLayoutVersion = _htmlVisualRoot.LayoutVersion; //---------------------------------------------------- int x = e.X; int y = e.Y; _mouseDownStartAt = startAt; _mousedownX = x; _mousedownY = y; CssBoxHitChain hitChain = GetFreeHitChain(); #if DEBUG hitChain.debugEventPhase = CssBoxHitChain.dbugEventPhase.MouseDown; #endif hitChain.SetRootGlobalPosition(x, y); //1. hittest BoxHitUtils.HitTest(startAt, x, y, hitChain); //2. propagate events SetEventOrigin(e, hitChain); ForEachOnlyEventPortalBubbleUp(e, hitChain, portal => { portal.PortalMouseDown(e); return(true); }); if (!e.CancelBubbling) { IUIEventListener prevMouseDownElement = _currentMouseDown; _currentMouseDown = null; //clear e.SetCurrentContextElement(null); ForEachEventListenerBubbleUp(e, hitChain, () => { //TODO: check accept keyboard _currentMouseDown = e.CurrentContextElement; e.CurrentContextElement.ListenMouseDown(e); if (prevMouseDownElement != null && prevMouseDownElement != _currentMouseDown) { prevMouseDownElement.ListenLostMouseFocus(_mouseLostFocus); } return(e.CancelBubbling); }); } //---------------------------------- //save mousedown hitchain _latestMouseDownChain = hitChain; }
public void MouseMove(UIMouseEventArgs e, CssBox startAt) { if (!_isBinded) { return; } if (startAt == null) { return; } //----------------------------------------- int x = e.X; int y = e.Y; if (e.IsDragging && _latestMouseDownChain != null) { //dragging *** , if changed if (this._mousedownX != x || this._mousedownY != y) { //handle mouse drag CssBoxHitChain hitChain = GetFreeHitChain(); hitChain.SetRootGlobalPosition(x, y); BoxHitUtils.HitTest(startAt, x, y, hitChain); SetEventOrigin(e, hitChain); //--------------------------------------------------------- //propagate mouse drag ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) => { portal.PortalMouseMove(e); return(true); }); //--------------------------------------------------------- if (!e.CancelBubbling) { ClearPreviousSelection(); if (_latestMouseDownChain.Count > 0 && hitChain.Count > 0) { if (this._htmlContainer.LayoutVersion != this.lastDomLayoutVersion) { //the dom has been changed so... //need to evaluate hitchain at mousedown position again int lastRootGlobalX = _latestMouseDownChain.RootGlobalX; int lastRootGlobalY = _latestMouseDownChain.RootGlobalY; _latestMouseDownChain.Clear(); _latestMouseDownChain.SetRootGlobalPosition(lastRootGlobalX, lastRootGlobalY); BoxHitUtils.HitTest(_mouseDownStartAt, lastRootGlobalX, lastRootGlobalY, _latestMouseDownChain); } //create selection range var newSelectionRange = new SelectionRange( _latestMouseDownChain, hitChain, this.ifonts); if (newSelectionRange.IsValid) { this._htmlContainer.SetSelection(newSelectionRange); } else { this._htmlContainer.SetSelection(null); } } else { this._htmlContainer.SetSelection(null); } ForEachEventListenerBubbleUp(e, hitChain, () => { e.CurrentContextElement.ListenMouseMove(e); return(true); }); } //--------------------------------------------------------- ReleaseHitChain(hitChain); } } else { //mouse move //--------------------------------------------------------- CssBoxHitChain hitChain = GetFreeHitChain(); hitChain.SetRootGlobalPosition(x, y); BoxHitUtils.HitTest(startAt, x, y, hitChain); SetEventOrigin(e, hitChain); //--------------------------------------------------------- ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) => { portal.PortalMouseMove(e); return(true); }); //--------------------------------------------------------- if (!e.CancelBubbling) { ForEachEventListenerBubbleUp(e, hitChain, () => { e.CurrentContextElement.ListenMouseMove(e); return(true); }); } ReleaseHitChain(hitChain); } }
public void MouseMove(UIMouseMoveEventArgs e, CssBox startAt) { if (!_isBinded) { return; } if (startAt == null) { return; } //----------------------------------------- int x = e.X; int y = e.Y; if (e.IsDragging && _latestMouseDownChain != null) { //dragging *** , if changed if (_mousedownX != x || _mousedownY != y) { //handle mouse drag CssBoxHitChain hitChain = GetFreeHitChain(); #if DEBUG hitChain.debugEventPhase = CssBoxHitChain.dbugEventPhase.MouseMove; #endif hitChain.SetRootGlobalPosition(x, y); BoxHitUtils.HitTest(startAt, x, y, hitChain); SetEventOrigin(e, hitChain); //--------------------------------------------------------- //propagate mouse drag ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) => { portal.PortalMouseMove(e); return(true); }); //--------------------------------------------------------- if (!e.CancelBubbling) { ClearPreviousSelection(); if (_latestMouseDownChain.Count > 0 && hitChain.Count > 0) { if (_htmlVisualRoot.LayoutVersion != _lastDomLayoutVersion) { //the dom has been changed so... //need to evaluate hitchain at mousedown position again int lastRootGlobalX = _latestMouseDownChain.RootGlobalX; int lastRootGlobalY = _latestMouseDownChain.RootGlobalY; _latestMouseDownChain.Clear(); _latestMouseDownChain.SetRootGlobalPosition(lastRootGlobalX, lastRootGlobalY); BoxHitUtils.HitTest(_mouseDownStartAt, lastRootGlobalX, lastRootGlobalY, _latestMouseDownChain); } //create selection range var newSelectionRange = new SelectionRange( _latestMouseDownChain, hitChain, _textService); if (newSelectionRange.IsValid) { _htmlVisualRoot.SetSelection(newSelectionRange); } else { _htmlVisualRoot.SetSelection(null); } } else { _htmlVisualRoot.SetSelection(null); } ForEachEventListenerBubbleUp(e, hitChain, () => { e.CurrentContextElement.ListenMouseMove(e); return(true); }); } //--------------------------------------------------------- ReleaseHitChain(hitChain); } } else { //mouse move //--------------------------------------------------------- CssBoxHitChain hitChain = GetFreeHitChain(); #if DEBUG hitChain.debugEventPhase = CssBoxHitChain.dbugEventPhase.MouseMove; #endif hitChain.SetRootGlobalPosition(x, y); BoxHitUtils.HitTest(startAt, x, y, hitChain); SetEventOrigin(e, hitChain); //--------------------------------------------------------- ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) => { portal.PortalMouseMove(e); return(true); }); //--------------------------------------------------------- if (!e.CancelBubbling) { ForEachEventListenerBubbleUp(e, hitChain, () => { e.CurrentContextElement.ListenMouseMove(e); return(true); }); } var cssbox = e.ExactHitObject as HtmlBoxes.CssBox; if (cssbox != null) { switch (cssbox.CursorName) { case Css.CssCursorName.IBeam: if (e.MouseCursorStyle != MouseCursorStyle.IBeam) { e.MouseCursorStyle = MouseCursorStyle.IBeam; } break; case Css.CssCursorName.Hand: case Css.CssCursorName.Pointer: if (e.MouseCursorStyle != MouseCursorStyle.Pointer) { e.MouseCursorStyle = MouseCursorStyle.Pointer; } break; case Css.CssCursorName.Default: if (e.MouseCursorStyle != MouseCursorStyle.Default) { e.MouseCursorStyle = MouseCursorStyle.Default; } break; } } else { var cssspan = e.ExactHitObject as HtmlBoxes.CssTextRun; if (cssspan != null) { cssbox = cssspan.OwnerBox; switch (cssbox.CursorName) { default: e.MouseCursorStyle = MouseCursorStyle.IBeam; break; case Css.CssCursorName.Hand: case Css.CssCursorName.Pointer: if (e.MouseCursorStyle != MouseCursorStyle.Pointer) { e.MouseCursorStyle = MouseCursorStyle.Pointer; } break; } } } ReleaseHitChain(hitChain); } }