2
0
Эх сурвалжийг харах

Fix some keydown events which should stop propagation, see #124.

Michael Ragazzon 5 жил өмнө
parent
commit
f9aee4533a

+ 4 - 0
Source/Core/ElementDocument.cpp

@@ -468,7 +468,10 @@ void ElementDocument::ProcessDefaultAction(Event& event)
 			if (Element* element = FindNextTabElement(event.GetTargetElement(), !event.GetParameter<bool>("shift_key", false)))
 			{
 				if(element->Focus())
+				{
 					element->ScrollIntoView(false);
+					event.StopPropagation();
+				}
 			}
 		}
 		// Process ENTER being pressed on a focusable object (emulate click)
@@ -480,6 +483,7 @@ void ElementDocument::ProcessDefaultAction(Event& event)
 			if (focus_node && focus_node->GetComputedValues().tab_index == Style::TabIndex::Auto)
 			{
 				focus_node->Click();
+				event.StopPropagation();
 			}
 		}
 	}

+ 2 - 0
Source/Core/Elements/WidgetDropDown.cpp

@@ -464,9 +464,11 @@ void WidgetDropDown::ProcessEvent(Event& event)
 		{
 		case Input::KI_UP:
 			SetSelection((selected_option - 1 + (int)options.size()) % (int)options.size());
+			event.StopPropagation();
 			break;
 		case Input::KI_DOWN:
 			SetSelection((selected_option + 1) % (int)options.size());
+			event.StopPropagation();
 			break;
 		default:
 			break;

+ 7 - 16
Source/Core/Elements/WidgetSlider.cpp

@@ -449,24 +449,15 @@ void WidgetSlider::ProcessEvent(Event& event)
 
 	case EventId::Keydown:
 	{
-		Input::KeyIdentifier key_identifier = (Input::KeyIdentifier) event.GetParameter< int >("key_identifier", 0);
+		const Input::KeyIdentifier key_identifier = (Input::KeyIdentifier) event.GetParameter< int >("key_identifier", 0);
 
-		switch (key_identifier)
+		const bool increment = (key_identifier == Input::KI_RIGHT && orientation == HORIZONTAL) || (key_identifier == Input::KI_DOWN && orientation == VERTICAL);
+		const bool decrement = (key_identifier == Input::KI_LEFT  && orientation == HORIZONTAL) || (key_identifier == Input::KI_UP   && orientation == VERTICAL);
+
+		if (increment || decrement)
 		{
-		case Input::KI_LEFT:
-			if (orientation == HORIZONTAL) SetBarPosition(OnLineDecrement());
-			break;
-		case Input::KI_UP:
-			if (orientation == VERTICAL) SetBarPosition(OnLineDecrement());
-			break;
-		case Input::KI_RIGHT:
-			if (orientation == HORIZONTAL) SetBarPosition(OnLineIncrement());
-			break;
-		case Input::KI_DOWN:
-			if (orientation == VERTICAL) SetBarPosition(OnLineIncrement());
-			break;
-		default:
-			break;
+			SetBarPosition(decrement ? OnLineDecrement() : OnLineIncrement());
+			event.StopPropagation();
 		}
 	}
 	break;