Browse Source

Make a public ElementDocument::GetStyleSheetContainer function.

Michael Ragazzon 4 years ago
parent
commit
001ef4c2e9
3 changed files with 26 additions and 24 deletions
  1. 7 7
      Include/RmlUi/Core/ElementDocument.h
  2. 3 1
      Source/Core/Context.cpp
  3. 16 16
      Source/Core/ElementDocument.cpp

+ 7 - 7
Include/RmlUi/Core/ElementDocument.h

@@ -84,15 +84,19 @@ public:
 	/// Returns the source address of this document.
 	const String& GetSourceURL() const;
 
-	/// Returns the document's style sheet.
+	/// Returns the document's compiled style sheet.
+	/// @note The style sheet may be regenerated when media query parameters change, invalidating the pointer.
 	const StyleSheet* GetStyleSheet() const override;
-	/// Sets the style sheet this document, and all of its children, uses.
-	void SetStyleSheetContainer(SharedPtr<StyleSheetContainer> style_sheet);
 	/// Reload the document's style sheet from source files.
 	/// Styles will be reloaded from <style> tags and external style sheets, but not inline 'style' attributes.
 	/// @note The source url originally used to load the document must still be a valid RML document.
 	void ReloadStyleSheet();
 
+	/// Returns the document's style sheet container.
+	const StyleSheetContainer* GetStyleSheetContainer() const;
+	/// Sets the style sheet this document, and all of its children, uses.
+	void SetStyleSheetContainer(SharedPtr<StyleSheetContainer> style_sheet);
+
 	/// Brings the document to the front of the document stack.
 	void PullToFront();
 	/// Sends the document to the back of the document stack.
@@ -151,10 +155,6 @@ private:
 	/// Searches forwards or backwards for a focusable element in the given substree
 	Element* SearchFocusSubtree(Element* element, bool forward);
 
-	/// Returns the active style sheet container for this element.
-	/// @warning Shared style sheet containers should be used with care, mainly used for proxy elements in the same context.
-	const SharedPtr<StyleSheetContainer>& GetStyleSheetContainer() const;
-
 	/// Sets the dirty flag on the layout so the document will format its children before the next render.
 	void DirtyLayout() override;
 	/// Returns true if the document has been marked as needing a re-layout.

+ 3 - 1
Source/Core/Context.cpp

@@ -1222,7 +1222,9 @@ void Context::CreateDragClone(Element* element)
 	// Set the style sheet on the cursor proxy.
 	if (ElementDocument* document = element->GetOwnerDocument())
 	{
-		static_cast<ElementDocument&>(*cursor_proxy).SetStyleSheetContainer(document->GetStyleSheetContainer());
+		// Borrow the target document's style sheet. Sharing style sheet containers should be used with care, and
+		// only within the same context.
+		static_cast<ElementDocument&>(*cursor_proxy).SetStyleSheetContainer(document->style_sheet_container);
 	}
 
 	// Set all the required properties and pseudo-classes on the clone.

+ 16 - 16
Source/Core/ElementDocument.cpp

@@ -180,19 +180,6 @@ const String& ElementDocument::GetSourceURL() const
 	return source_url;
 }
 
-// Sets the style sheet this document, and all of its children, uses.
-void ElementDocument::SetStyleSheetContainer(SharedPtr<StyleSheetContainer> _style_sheet_container)
-{
-	RMLUI_ZoneScoped;
-
-	if (style_sheet_container == _style_sheet_container)
-		return;
-
-	style_sheet_container = std::move(_style_sheet_container);
-	
-	DirtyMediaQueries();
-}
-
 // Returns the document's style sheet.
 const StyleSheet* ElementDocument::GetStyleSheet() const
 {
@@ -202,9 +189,22 @@ const StyleSheet* ElementDocument::GetStyleSheet() const
 }
 
 // Returns the document's style sheet container.
-const SharedPtr<StyleSheetContainer>& ElementDocument::GetStyleSheetContainer() const
+const StyleSheetContainer* ElementDocument::GetStyleSheetContainer() const
 {
-	return style_sheet_container;
+	return style_sheet_container.get();
+}
+
+// Sets the style sheet this document, and all of its children, uses.
+void ElementDocument::SetStyleSheetContainer(SharedPtr<StyleSheetContainer> _style_sheet_container)
+{
+	RMLUI_ZoneScoped;
+
+	if (style_sheet_container == _style_sheet_container)
+		return;
+
+	style_sheet_container = std::move(_style_sheet_container);
+
+	DirtyMediaQueries();
 }
 
 // Reload the document's style sheet from source files.
@@ -228,7 +228,7 @@ void ElementDocument::ReloadStyleSheet()
 		return;
 	}
 
-	SetStyleSheetContainer(static_cast<ElementDocument*>(temp_doc.get())->GetStyleSheetContainer());
+	SetStyleSheetContainer(static_cast<ElementDocument*>(temp_doc.get())->style_sheet_container);
 }
 
 void ElementDocument::DirtyMediaQueries()