/// <summary>Sets the pressure level.</summary> public void SetPressure(float v) { // Was it up before? bool wasUp = (Pressure == 0f); // Set pressure: Pressure = v; // If it's non-zero then we'll need to grab the clicked object: if (v == 0f) { if (wasUp) { // No change. } else { // It's up now. Clear: Element oldActivePressed = ActivePressed; // Clear: ActivePressed = null; if (oldActivePressed != null) { // Refresh CSS (active): (oldActivePressed as IRenderableNode).ComputedStyle.RefreshLocal(); } // Trigger up event. MouseEvent e = new MouseEvent(DocumentX, DocumentY, ButtonID, false); e.trigger = this; e.SetModifiers(); e.EventType = "mouseup"; if (oldActivePressed == null) { Input.Unhandled.dispatchEvent(e); } else { oldActivePressed.dispatchEvent(e); } // Click if needed: if (oldActivePressed == ActiveOver && DragStatus == 0) { // Click! e.Reset(); e.trigger = this; e.SetModifiers(); e.EventType = "click"; if (oldActivePressed == null) { Input.Unhandled.dispatchEvent(e); } else if (oldActivePressed.dispatchEvent(e)) { // Perform the default: HtmlElement h = (oldActivePressed as HtmlElement); if (h != null) { h.OnClickEvent(e); } // Clear selection if there is one: (oldActivePressed.document as HtmlDocument).clearSelection(); } } if (FireTouchEvents) { // Trigger a touchend event too: TouchEvent te = new TouchEvent("touchend"); te.trigger = this; te.SetModifiers(); te.SetTrusted(); te.clientX = DocumentX; te.clientY = DocumentY; if (oldActivePressed == null) { Input.Unhandled.dispatchEvent(te); } else { oldActivePressed.dispatchEvent(te); } } if (DragStatus == DRAGGING) { // Trigger dragend: DragEvent de = new DragEvent("dragend"); de.trigger = this; de.SetModifiers(); de.SetTrusted(); de.clientX = ScreenX; de.clientY = ScreenY; if (oldActivePressed.dispatchEvent(de)) { // Trigger a drop event next: de.Reset(); de.EventType = "drop"; if (ActiveOver != null && ActiveOver.dispatchEvent(de)) { // Proceed to try and drop it into the dropzone (ActiveOver). } } } else if (DragStatus == SELECTING) { // Finished selection - trigger selectionend: Dom.Event sc = new Dom.Event("selectionend"); sc.SetTrusted(); // Dispatch on the element: oldActivePressed.dispatchEvent(sc); } // Always clear drag status: DragStatus = 0; MinDragDistance = 0f; } } else if (wasUp) { // It was up and it's now just gone down. // Cache position: DownDocumentX = DocumentX; DownDocumentY = DocumentY; // Cache down: ActivePressed = ActiveOver; // Trigger down event. if (ActivePressed != null) { // Refresh CSS (active): (ActivePressed as IRenderableNode).ComputedStyle.RefreshLocal(); } // Trigger down event. MouseEvent e = new MouseEvent(DocumentX, DocumentY, ButtonID, true); e.trigger = this; e.EventType = "mousedown"; e.SetModifiers(); if (ActivePressed == null) { Input.Unhandled.dispatchEvent(e); } else { ActivePressed.dispatchEvent(e); } if (FireTouchEvents) { // Trigger a touchend event too: TouchEvent te = new TouchEvent("touchstart"); te.trigger = this; te.clientX = DocumentX; te.clientY = DocumentY; te.SetTrusted(); te.SetModifiers(); if (ActivePressed == null) { Input.Unhandled.dispatchEvent(te); } else { ActivePressed.dispatchEvent(te); } } } }