Browse Source

Added support for 'pointer-events: none'

Michael 7 years ago
parent
commit
db0aff2a8d

+ 2 - 0
Include/Rocket/Core/Element.h

@@ -250,6 +250,8 @@ public:
 	int GetDisplay();
 	/// Returns 'white-space' property value from element's style or local cache.
 	int GetWhitespace();
+	/// Returns 'pointer-events' property value from element's style or local cache.
+	int GetPointerEvents();
 
 	/// Returns 'line-height' property value from element's style or local cache.
 	const Property *GetLineHeightProperty();

+ 2 - 0
Include/Rocket/Core/StyleSheetKeywords.h

@@ -113,6 +113,8 @@ const int TAB_INDEX_AUTO = 1;
 const int FOCUS_NONE = 0;
 const int FOCUS_AUTO = 1;
 
+const int POINTER_EVENTS_AUTO = 0;
+const int POINTER_EVENTS_NONE = 1;
 }
 }
 

+ 5 - 0
Source/Core/Context.cpp

@@ -1100,6 +1100,7 @@ Element* Context::GetElementAtPoint(const Vector2f& point, const Element* ignore
 		}
 	}
 
+
 	// Check any elements within our stacking context. We want to return the lowest-down element
 	// that is under the cursor.
 	if (element->local_stacking_context)
@@ -1130,6 +1131,10 @@ Element* Context::GetElementAtPoint(const Vector2f& point, const Element* ignore
 		}
 	}
 
+	// Ignore elements whose pointer events are disabled
+	if (element->GetPointerEvents() == POINTER_EVENTS_NONE)
+		return NULL;
+
 	// Check if the point is actually within this element.
 	bool within_element = element->IsPointWithinElement(point);
 	if (within_element)

+ 5 - 0
Source/Core/Element.cpp

@@ -595,6 +595,11 @@ int Element::GetWhitespace()
 	return style->GetWhitespace();
 }
 
+int Element::GetPointerEvents()
+{
+	return style->GetPointerEvents();
+}
+
 const Property *Element::GetLineHeightProperty()
 {
 	return style->GetLineHeightProperty();

+ 5 - 0
Source/Core/ElementStyle.cpp

@@ -812,6 +812,11 @@ int ElementStyle::GetWhitespace()
 	return cache->GetWhitespace();
 }
 
+int ElementStyle::GetPointerEvents()
+{
+	return cache->GetPointerEvents();
+}
+
 const Property *ElementStyle::GetLineHeightProperty()
 {
 	return cache->GetLineHeightProperty();

+ 2 - 0
Source/Core/ElementStyle.h

@@ -168,6 +168,8 @@ public:
 	int GetDisplay();
 	/// Returns 'white-space' property value from element's style or local cache.
 	int GetWhitespace();
+	/// Returns 'pointer-events' property value from element's style or local cache.
+	int GetPointerEvents();
 
 	/// Returns 'line-height' property value from element's style or local cache.
 	const Property *GetLineHeightProperty();

+ 15 - 1
Source/Core/ElementStyleCache.cpp

@@ -41,7 +41,8 @@ ElementStyleCache::ElementStyleCache(ElementStyle *style) : style(style),
 	local_width(NULL), local_height(NULL), have_local_width(false), have_local_height(false),
 	overflow_x(-1), overflow_y(-1),
 	position(-1), float_(-1), display(-1), whitespace(-1),
-	line_height(NULL), text_align(-1), text_transform(-1), vertical_align(NULL)
+	line_height(NULL), text_align(-1), text_transform(-1), vertical_align(NULL),
+	pointer_events(-1)
 {
 }
 
@@ -65,6 +66,7 @@ void ElementStyleCache::ClearInherited()
 	ClearTextAlign();
 	ClearTextTransform();
 	ClearVerticalAlign();
+	ClearPointerEvents();
 }
 
 void ElementStyleCache::ClearOffset()
@@ -138,6 +140,11 @@ void ElementStyleCache::ClearVerticalAlign()
 	vertical_align = NULL;
 }
 
+void ElementStyleCache::ClearPointerEvents()
+{
+	pointer_events = -1;
+}
+
 void ElementStyleCache::GetOffsetProperties(const Property **o_top, const Property **o_bottom, const Property **o_left, const Property **o_right )
 {
 	if (o_top)
@@ -347,6 +354,13 @@ int ElementStyleCache::GetWhitespace()
 	return whitespace;
 }
 
+int ElementStyleCache::GetPointerEvents()
+{
+	if (pointer_events < 0)
+		pointer_events = style->GetProperty(POINTER_EVENTS)->Get< int >();
+	return pointer_events;
+}
+
 const Property *ElementStyleCache::GetLineHeightProperty()
 {
 	if (!line_height)

+ 4 - 0
Source/Core/ElementStyleCache.h

@@ -71,6 +71,7 @@ public:
 	void ClearTextAlign();
 	void ClearTextTransform();
 	void ClearVerticalAlign();
+	void ClearPointerEvents();
 
 	/// Returns 'top', 'bottom', 'left' and 'right' properties from element's style or local cache.
 	void GetOffsetProperties(const Property **top, const Property **bottom, const Property **left, const Property **right );
@@ -95,6 +96,8 @@ public:
 	int GetDisplay();
 	/// Returns 'white-space' property value from element's style or local cache.
 	int GetWhitespace();
+	/// Returns 'pointer-events' property value from element's style or local cache.
+	int GetPointerEvents();
 
 	/// Returns 'line-height' property value from element's style or local cache.
 	const Property *GetLineHeightProperty();
@@ -126,6 +129,7 @@ private:
 	int text_align;
 	int text_transform;
 	const Property *vertical_align;
+	int pointer_events;
 };
 
 }

+ 1 - 0
Source/Core/StringCache.cpp

@@ -98,6 +98,7 @@ const String TAB_INDEX = "tab-index";
 const String SCROLLBAR_MARGIN = "scrollbar-margin";
 const String SCROLL_DEFAULT_STEP_SIZE = "scroll-default-step-size";
 const String OPACITY = "opacity";
+const String POINTER_EVENTS = "pointer-events";
 
 const String MOUSEDOWN = "mousedown";
 const String MOUSESCROLL = "mousescroll";

+ 1 - 0
Source/Core/StringCache.h

@@ -101,6 +101,7 @@ extern const String TAB_INDEX;
 extern const String SCROLLBAR_MARGIN;
 extern const String SCROLL_DEFAULT_STEP_SIZE;
 extern const String OPACITY;
+extern const String POINTER_EVENTS;
 
 extern const String MOUSEDOWN;
 extern const String MOUSESCROLL;

+ 2 - 0
Source/Core/StyleSheetSpecification.cpp

@@ -267,6 +267,8 @@ void StyleSheetSpecification::RegisterDefaultProperties()
 
 	RegisterProperty(SCROLLBAR_MARGIN, "0", false, false).AddParser("number");
 	RegisterProperty(OPACITY, "1", true, false).AddParser("number");
+
+	RegisterProperty(POINTER_EVENTS, "auto", true, false).AddParser("keyword", "auto, none");
 }
 
 }