public override bool OnClick(UIEvent clickEvent){
			
			base.OnClick(clickEvent);
			clickEvent.stopPropagation();
			
			return true;
		}
Example #2
0
		public override bool OnClick(UIEvent clickEvent){
			
			// No bubbling:
			clickEvent.stopPropagation();
			
			return true;
		}
		public override void Clicked(UIEvent clickEvent){
			// Track where the mouse started off:
			MouseY=clickEvent.clientY;
			
			// And where the bar started off too:
			StartY=Element.style.Computed.PositionTop;
		}
		public override bool OnClick(UIEvent clickEvent){
			base.OnClick(clickEvent);
			
			if(Details==null){
				return false;
			}
				
			if(!clickEvent.heldDown){
				// Hide/show the details element.
				
				// Grab the details computed style:
				ComputedStyle computed=Details.Style.Computed;
				
				// The display it's going to:
				string display;
				
				// Is it currently visible?
				if(computed.Display==DisplayType.None){
					// Nope! Show it.
					display="block";
				}else{
					// Yep - hide it.
					display="none";
				}
				
				// Change it's display:
				computed.ChangeTagProperty("display",new Css.Value(display,Css.ValueType.Text));
				
			}
			
			return true;
		}
		public override bool OnClick(UIEvent clickEvent){
			
			// No bubbling:
			clickEvent.stopPropagation();
			
			if(clickEvent.heldDown || Dropdown==null){
				return true;
			}
			
			Dropdown.SetSelected(Element);
			Dropdown.Hide();
			
			return true;
		}
Example #6
0
		public override bool OnClick(UIEvent clickEvent){
			// Who wants the click? That's the for element:
			Element forElement=GetFor();
			
			if(forElement!=null){
				// Prevent any propagation - we sure don't want it clicking this element again (which may occur if
				// forElement is one of this elements kids and it propagated upwards).
				clickEvent.stopPropagation();
				// Click it:
				forElement.GotClicked(clickEvent);
			}
			// Run this elements onmousedown/up etc.
			base.OnClick(clickEvent);
			
			return true;
		}
		/// <summary>Runs the given function held in the named attribute (e.g. onkeydown) and checks if that function blocked
		/// the event. In the case of a blocked event, no default action should occur.</summary>
		/// <param name="attribute">The name of the attribute, e.g. onkeydown.</param>
		/// <param name="uiEvent">A standard UIEvent containing e.g. key/mouse information.</param>
		public bool RunBlocked(string attribute,UIEvent uiEvent){
			
			// Run the function:
			object result=Run(attribute,uiEvent);
			
			if(result!=null && result.GetType()==typeof(bool)){
				// It returned true/false - was it false?
				
				if(!(bool)result){
					// Returned false - Blocked it.
					return true;
				}
				
			}
			
			return uiEvent.cancelBubble;
		}
		/// <summary>Runs a click with the given UI event based on where on the UI this hit occured.</summary>
		public bool RunClick(UIEvent uiEvent){
			if(!Success){
				return false;
			}
			
			// Update coords:
			uiEvent.clientX=MouseX;
			uiEvent.clientY=MouseY;
			
			// Does it have a fully resolved element?
			if(HitElement!=null){
				// Yes it does - immediately bubble downwards from this element:
				Input.ClickOn(HitElement,uiEvent);
				return true;
			}else{
				// Nope; Instead treat this like any ordinary 2D click but on a WorldUI.
				return OnWorldUI.document.html.RunClickOnKids(uiEvent);
			}
		}
		/// <summary>Runs a mouse over event for the UI, if any, that this hit occured on.</summary>
		public void RunMouseOver(UIEvent mouseEvent){
			
			if(!Success){
				return;
			}
			
			// Update coords:
			mouseEvent.clientX=MouseX;
			mouseEvent.clientY=MouseY;
			
			Input.MouseY=MouseY;
			Input.MouseX=MouseX;
			
			// Does it have a fully resolved element?
			if(HitElement!=null){
				// Yes it does - start from that and bubble directly.
				Input.MouseOn(HitElement,mouseEvent);
			}else{
				// Nope - Do the mouseover event here with the WorldUI:
				OnWorldUI.document.RunMouseMove(mouseEvent);
			}
			
		}
//--------------------------------------
		/// <summary>Called when the element is clicked (or the mouse is released over it).</summary>
		/// <param name="clickEvent">The UIEvent describing the click.</param>
		public virtual bool OnClick(UIEvent clickEvent){
			return Element.OnClickEvent(clickEvent);
		}
		public override void OnMouseMove(UIEvent mouseEvent){
			int deltaX=mouseEvent.clientX-MouseX;
			
			if(deltaX==0){
				return;
			}
			
			ScrollBy(deltaX,false,true);
		}
Example #13
0
		public override bool OnClick(UIEvent clickEvent){
			
			if(!clickEvent.heldDown && Element.MouseWasDown()){
				
				if(Dropped){
					Hide();
				}else{
					Drop();
				}
				
			}
			
			base.OnClick(clickEvent);
			clickEvent.stopPropagation();
			
			return true;
		}
Example #14
0
		/// <summary>Tells the UI the mouse was clicked or released.</summary>
		/// <param name="x">The x coordinate of the mouse in pixels from the left of the screen.</param>
		/// <param name="y">The y coordinate of the mouse in pixels from the top of the screen.</param>
		/// <param name="mouseDown">True if the button is now down.</param>
		/// <returns>True if the mouse was on the UI.</returns>
		private static bool RunClick(int x,int y,bool mouseDown,out UIEvent uiEvent){
			uiEvent=new UIEvent(x,y,mouseDown);
			
			// Which button?
			if(Event.current!=null){
				uiEvent.keyCode=Event.current.button;
			}
			
			if(UI.document==null || UI.document.html==null){
				return false;
			}
			
			int invertedY=ScreenInfo.ScreenY-1-y;
			
			bool result=false;
			
			if(Mode==InputMode.Screen){
				result=UI.document.html.RunClickOnKids(uiEvent);
			}else if(Mode==InputMode.Physics){
				// Screen physics cast here.
				
				RaycastHit uiHit;
				if(Physics.Raycast(UI.GUICamera.ScreenPointToRay(new Vector2(x,invertedY)),out uiHit)){
					// Did it hit the main UI?
					HitResult hit=HandleUIHit(uiHit);
					result=hit.Success;
					
					if(result){
						// Yes - As this is the main UI, We must have a HitElement available. All we need to do is ClickOn it!
						ClickOn(hit.HitElement,uiEvent);
					}
				}
				
			}
			
			if(!result && WorldInputMode!=InputMode.None){
				// Didn't hit the main UI - handle clicks on WorldUI's.
				RaycastHit worldUIHit;
				
				if(CameraFor3DInput==null){
					CameraFor3DInput=Camera.main;
				}
				
				bool hitSuccess=false;
				
				if(OnResolve3D!=null){
					hitSuccess=OnResolve3D(out worldUIHit,uiEvent);
				}else{
					hitSuccess=Physics.Raycast(CameraFor3DInput.ScreenPointToRay(new Vector2(x,invertedY)),out worldUIHit);
				}
				
				if(hitSuccess){
					// Did it hit a worldUI?
					HitResult hit=HandleWorldUIHit(worldUIHit);
					result=hit.Success;
					
					if(result){
						// Yes it did.
						result=hit.RunClick(uiEvent);
					}
				}
			}
			
			// Clear any LastMouseDown entries:
			if(!mouseDown){
				
				// Clear their active state:
				for(int i=LastMouseDown.Count-1;i>=0;i--){
					// Get the element:
					Element element=LastMouseDown[i];
					
					// Get computed style:
					Css.ComputedStyle computed=element.Style.Computed;
					
					// Clear active:
					computed.UnsetModifier("active");
					
					// Still got the mouse over it?
					if(element.MousedOver!=MouseOverState.Out){
						// Yep! Re-apply hover:
						computed.Hover();
					}
				}
				
				// Clear the set:
				LastMouseDown.Clear();
			}
			
			return result;
		}
Example #15
0
		/// <summary>Runs a click which may bubble all the way to the root from the given element.</summary>
		/// <param name="element">The element to run a click on.</param>
		/// <param name="uiEvent">The event that represents the click.</param>
		public static void ClickOn(Element element,UIEvent uiEvent){
			if(uiEvent.cancelBubble || element==null || element.Handler.IgnoreSelfClick){
				return;
			}
			element.GotClicked(uiEvent);
			ClickOn(element.ParentNode,uiEvent);
		}
Example #16
0
		public override bool OnClick(UIEvent clickEvent){
			
			// Did the mouse go up, and was the element clicked down on too?
			if(!clickEvent.heldDown && Element.MouseWasDown()){
				
				// Focus it:
				Element.Focus();
				
				if(Type==InputType.Submit){
					// Find the form and then attempt to submit it.
					FormTag form=Element.form;
					if(form!=null){
						form.submit();
					}
				}else if(IsScrollInput()){
					// Clicked somewhere on a scrollbar:
					// Figure out where the click was, and scroll there.
				}else if(Type==InputType.Radio){
					Select();
				}else if(Type==InputType.Checkbox){
					
					if(Checked){
						Unselect();
					}else{
						Select();
					}
					
				}else if(IsTextInput()){
					// Move the cursor to the click point:
					int localClick=clickEvent.clientX-Element.Style.Computed.OffsetLeft + Element.Style.Computed.ScrollLeft;
					int index=0;
					
					if(Element.childNodes.Count>1){
						// Note: If it's equal to 1, ele[0] is the cursor.
						TextElement text=(TextElement)(Element.childNodes[0]);
						if(text!=null){
							index=text.LetterIndex(localClick);
						}
					}
					
					MoveCursor(index,true);
				}
				
			}
			
			base.OnClick(clickEvent);
			clickEvent.stopPropagation();
			
			return true;
		}
		/// <summary>Runs the keyup events.</summary>
		/// <param name="e">The event which has occured.</param>
		public bool RunKeyUp(UIEvent e){
			
			if(KeyUp!=null && KeyUp(e)){
				return true;
			}
			
			if(onkeyup!=null){
				onkeyup.Run(e);
			}
			
			return false;
		}
//--------------------------------------
Example #19
0
		public override bool OnClick(UIEvent clickEvent){
			base.OnClick(clickEvent);
			
			if(!clickEvent.heldDown){
				// Time to go to our Href.
				
				#if MOBILE || UNITY_METRO
				
				// First, look for <source> elements.
				
				// Grab the kids:
				List<Element> kids=Element.childNodes;
				
				if(kids!=null){
					// For each child, grab it's src value. Favours the most suitable protocol for this platform (e.g. market:// on android).
					
					foreach(Element child in kids){
						
						if(child.Tag!="source"){
							continue;
						}
						
						// Grab the src:
						string childSrc=child["src"];
						
						if(childSrc==null){
							continue;
						}
						
						// Get the optional type - it can be Android,W8,IOS,Blackberry:
						string type=child["type"];
						
						if(type!=null){
							type=type.Trim().ToLower();
						}
						
						#if UNITY_ANDROID
							
							if(type=="android" || childSrc.StartsWith("market:")){
								
								Href=childSrc;
								
							}
							
						#elif UNITY_WP8 || UNITY_METRO
						
							if(type=="w8" || type=="wp8" || type=="windows" || childSrc.StartsWith("ms-windows-store:")){
								
								Href=childSrc;
								
							}
							
						#elif UNITY_IPHONE
							
							if(type=="ios" || childSrc.StartsWith("itms:") || childSrc.StartsWith("itms-apps:")){
								
								Href=childSrc;
								
							}
							
							
						#endif
						
					}
					
				}
				
				#endif
					
				
				if(!string.IsNullOrEmpty(Href)){
					FilePath path=new FilePath(Href,Element.Document.basepath,false);
					
					// Do we have a file protocol handler available?
					FileProtocol fileProtocol=path.Handler;
					
					if(fileProtocol!=null){
						fileProtocol.OnFollowLink(Element,path);
					}
				}
				
				clickEvent.stopPropagation();
			}
			
			return true;
		}
Example #20
0
		/// <summary>Runs a mouseover which may bubble all the way to the root from the given element.</summary>
		/// <param name="element">The element to run a mouseover on.</param>
		/// <param name="uiEvent">The event that represents the click.</param>
		public static void MouseOn(Element element,UIEvent uiEvent){
			if(uiEvent.cancelBubble || element==null || element.Handler.IgnoreSelfClick){
				return;
			}
			
			if(element.GetType()!=typeof(TextElement)){
				element.MouseOver(uiEvent);
			}
			
			MouseOn(element.ParentNode,uiEvent);
		}
Example #21
0
		public override void OnKeyPress(UIEvent pressEvent){
			// We want to fire the nitro event first:
			base.OnKeyPress(pressEvent);
			
			// How long is the current value?
			int length=0;
			
			if(Value!=null){
				length=Value.Length;
			}
			
			// Is the cursor too far over?
			if(CursorIndex>length){
				MoveCursor(0);
			}
			
			if(pressEvent.cancelBubble){
				return;
			}
			
			if(pressEvent.heldDown){
				if(IsTextInput()){
					// Add to value if pwd/text, unless it's backspace:
					string value=Value;
					
					if(!char.IsControl(pressEvent.character) && pressEvent.character!='\0'){
						
						// Drop the character in the string at cursorIndex
						if(value==null){
							value=""+pressEvent.character;
						}else{
							value=value.Substring(0,CursorIndex)+pressEvent.character+value.Substring(CursorIndex,value.Length-CursorIndex);
						}
						
						SetValue(value);
						MoveCursor(CursorIndex+1);
						return;
					}
					
					// Grab the keycode:
					KeyCode key=pressEvent.unityKeyCode;
					
					if(key==KeyCode.LeftArrow){
						MoveCursor(CursorIndex-1,true);
					}else if(key==KeyCode.RightArrow){
						MoveCursor(CursorIndex+1,true);
					}else if(key==KeyCode.Backspace){
						// Delete the character before the cursor.
						if(string.IsNullOrEmpty(value)||CursorIndex==0){
							return;
						}
						value=value.Substring(0,CursorIndex-1)+value.Substring(CursorIndex,value.Length-CursorIndex);
						int index=CursorIndex;
						SetValue(value);
						MoveCursor(index-1);
					}else if(key==KeyCode.Delete){
						// Delete the character after the cursor.
						if(string.IsNullOrEmpty(value)||CursorIndex==value.Length){
							return;
						}
						
						value=value.Substring(0,CursorIndex)+value.Substring(CursorIndex+1,value.Length-CursorIndex-1);
						SetValue(value);
					}else if(key==KeyCode.Return || key==KeyCode.KeypadEnter){
						// Does the form have a submit button? If so, submit now.
						// Also call a convenience (non-standard) "onenter" method.
						
						FormTag form=Element.form;
						if(form!=null && form.HasSubmitButton){
							form.submit();
						}
						
						return;
					}else if(key==KeyCode.Home){
						// Hop to the start:
						
						MoveCursor(0,true);
						
					}else if(key==KeyCode.End){
						// Hop to the end:
						
						int maxCursor=0;
						
						if(value!=null){
							maxCursor=value.Length;
						}
						
						MoveCursor(maxCursor,true);
						
					}else if(pressEvent.ctrlKey){
						
						if(key==KeyCode.V){
							
							// Run the onpaste function.
							if(Element.RunBlocked("onpaste",pressEvent)){
								// It blocked it.
								return;
							}
							
							// Paste the text, stripping any newlines:
							string textToPaste=Clipboard.Paste().Replace("\r","").Replace("\n","");
							
							if(!string.IsNullOrEmpty(textToPaste)){
								// Drop the character in the string at cursorIndex
								if(value==null){
									value=""+textToPaste;
								}else{
									value=value.Substring(0,CursorIndex)+textToPaste+value.Substring(CursorIndex,value.Length-CursorIndex);
								}
								
								SetValue(value);
								MoveCursor(CursorIndex+textToPaste.Length);
							}
							
						}else if(key==KeyCode.C){
							
							// Run the oncopy function.
							if(Element.RunBlocked("oncopy",pressEvent)){
								// It blocked it.
								return;
							}
							
							Clipboard.Copy(value);
						}
						
					}
					
				}
			}
		}
		/// <summary>Called when the mouse moves over this document.</summary>
		/// <param name="e">The mouse event containing the position.</param>
		public bool RunMouseMove(UIEvent e){
			
			// Run mouse over on the HTML element (and internally bubbles to it's kids):
			bool result=html.RunMouseOver(e);
			
			// Run the mousemove C# event:
			if(MouseMove!=null){
				MouseMove(e);
			}
			
			// Run the Nitro event:
			if(onmousemove!=null){
				// Run the Nitro event:
				onmousemove.Run(e);
			}
			
			return result;
		}
		/// <summary>Runs the keydown events.</summary>
		/// <param name="e">The event which has occured.</param>
		public bool RunKeyDown(UIEvent e){
			
			if(KeyDown!=null && KeyDown(e)){
				return true;
			}
			
			if(onkeydown!=null){
				onkeydown.Run(e);
			}
			
			return false;
		}
Example #24
0
		/// <summary>Tells the UI a key was pressed.</summary>
		/// <param name="down">True if the key is now down.</param>
		/// <param name="keyCode">The keycode of the key</param>
		/// <param name="character">The character entered.</param>
		/// <returns>True if the UI consumed the keypress.</returns>
		public static bool OnKeyPress(bool down,char character,int keyCode){
			UIEvent uiEvent=new UIEvent(keyCode,character,down);
			
			// Set the current event:
			uiEvent.unityEvent=Event.current;
			
			if(down){
				
				if(UI.document.RunKeyDown(uiEvent)){
					return true;
				}
				
			}else{
				
				if(UI.document.RunKeyUp(uiEvent)){
					return true;
				}
				
			}
			
			if(Focused==null){
				return false;
			}
			
			if(!Focused.isRooted){
				
				// It got removed.
				Focused.Unfocus();
				
				return false;
			}
			
			Focused.Handler.OnKeyPress(uiEvent);
			return true;
		}
		public override void OnMouseMove(UIEvent mouseEvent){
			int deltaY=mouseEvent.clientY-MouseY;
			
			if(deltaY==0){
				return;
			}
			
			ScrollBy(deltaY,false,true);
		}
		/// <summary>Called on the focused element when a key is pressed or released.</summary>
		/// <param name="pressEvent">The UIEvent describing the press; e.g. which key.</param>
		public virtual void OnKeyPress(UIEvent pressEvent){
			Element.OnKeyPress(pressEvent);
		}
		/// <summary>Called by a tag handler when a key press occurs.</summary>
		/// <param name="clickEvent">The event that represents the key press.</param>
		public void OnKeyPress(UIEvent pressEvent){
			
			pressEvent.target=this;
			
			if(pressEvent.heldDown){
				Run("onkeydown",pressEvent);
				if(OnKeyDown!=null){
					OnKeyDown(pressEvent);
				}
			}else{
				Run("onkeyup",pressEvent);
				if(OnKeyUp!=null){
					OnKeyUp(pressEvent);
				}
			}
		}
		/// <summary>Called on the focused element when the mouse is moved.</summary>
		/// <param name="clickEvent">The UIEvent describing the click.</param>
		public virtual void OnMouseMove(UIEvent moveEvent){
			Element.OnMouseMoveEvent(moveEvent);
		}
Example #29
0
		public override void OnMouseMove(UIEvent e){
			base.OnMouseMove(e);
			
			if(e.leftMouseDown){
				// Left mouse button is currently down.
				
				// Grab the dropdown box:
				Element dropdown=GetDropdownBox();
				
				// Is it outside the select menu and outside the dropdown box?
				if(	!Element.IsMousedOver() && !dropdown.IsMousedOver() ){
					// Yep it is - Clicked outside the dropdown menu.
					
					// Hide it now:
					Hide();
					
				}
				
			}
			
		}
Example #30
0
		/// <summary>Checks if the mouse is over the UI and runs the mouse over methods.</summary>
		/// <param name="x">The x coordinate of the mouse in pixels from the left of the screen.</param>
		/// <param name="y">The y coordinate of the mouse in pixels from the top of the screen.</param>
		/// <returns>True if the mouse was over the UI.</returns>
		public static bool OnMouseOver(int x,int y){
			MouseY=y;
			MouseX=x;
			
			if(UI.document==null||UI.document.html==null){
				return false;
			}
			
			#if MOBILE
			if(!MouseoverActive){
				return false;
			}
			#endif
			
			UIEvent mouseEvent=new UIEvent(x,y,false);
			bool result=false;
			
			int invertedY=ScreenInfo.ScreenY-1-y;
			
			if(Mode==InputMode.Screen){
				
				// Run the mouse over on the main UI:
				result=UI.document.RunMouseMove(mouseEvent);
				
			}else if(Mode==InputMode.Physics){
				// Screen physics cast here. 
				RaycastHit uiHit;
				
				if(Physics.Raycast(UI.GUICamera.ScreenPointToRay(new Vector2(x,invertedY)),out uiHit)){
					HitResult hit=HandleUIHit(uiHit);
					result=hit.Success;
					
					if(result){
						// Great! As this is the main UI, We have a HitElement available.
						// Start from that and bubble the event to the root.
						MouseOn(hit.HitElement,mouseEvent);
					}
					
				}
				
			}
			
			if(!result && WorldInputMode!=InputMode.None){
				// World UI input time.
				RaycastHit worldUIHit;
				
				if(CameraFor3DInput==null){
					CameraFor3DInput=Camera.main;
				}
				
				bool hitSuccess=false;
				
				if(OnResolve3D!=null){
					hitSuccess=OnResolve3D(out worldUIHit,mouseEvent);
				}else{
					hitSuccess=Physics.Raycast(CameraFor3DInput.ScreenPointToRay(new Vector2(x,invertedY)),out worldUIHit);
				}
				
				if(hitSuccess){
					LatestRayHit=worldUIHit;
					// Hit something - was it a worldUI?
					HitResult hit=HandleWorldUIHit(worldUIHit);
					result=hit.Success;
					if(result){
						// Yes it was.
						hit.RunMouseOver(mouseEvent);
					}
				}else{
					LatestRayHit=default(RaycastHit);
				}
			}
			
			if(!result){
				ClearMouseOvers(mouseEvent,0);
			}
			return result;
		}