Sfoglia il codice sorgente

Refactor: Use common `IsScrollContainer` function

Michael Ragazzon 1 anno fa
parent
commit
b6162ffc90

+ 2 - 3
Source/Core/ElementDocument.cpp

@@ -37,6 +37,7 @@
 #include "DocumentHeader.h"
 #include "ElementStyle.h"
 #include "EventDispatcher.h"
+#include "Layout/LayoutDetails.h"
 #include "Layout/LayoutEngine.h"
 #include "StreamFile.h"
 #include "StyleSheetFactory.h"
@@ -93,9 +94,7 @@ namespace {
 	bool IsScrollContainer(Element* element)
 	{
 		const auto& computed = element->GetComputedValues();
-		if (computed.overflow_x() != Style::Overflow::Visible || computed.overflow_y() != Style::Overflow::Visible)
-			return true;
-		return false;
+		return LayoutDetails::IsScrollContainer(computed.overflow_x(), computed.overflow_y());
 	}
 
 	int GetNavigationHeuristic(const BoundingBox& source, const BoundingBox& target, NavigationSearchDirection direction)

+ 5 - 0
Source/Core/Layout/ContainerBox.cpp

@@ -66,6 +66,11 @@ void ContainerBox::AddRelativeElement(Element* element)
 		relative_elements.push_back(element);
 }
 
+bool ContainerBox::IsScrollContainer() const
+{
+	return LayoutDetails::IsScrollContainer(overflow_x, overflow_y);
+}
+
 void ContainerBox::ClosePositionedElements()
 {
 	// Any relatively positioned elements that we act as containing block for may need to be have their positions

+ 2 - 2
Source/Core/Layout/ContainerBox.h

@@ -43,8 +43,6 @@ namespace Rml {
 */
 class ContainerBox : public LayoutBox {
 public:
-	bool IsScrollContainer() const { return overflow_x != Style::Overflow::Visible || overflow_y != Style::Overflow::Visible; }
-
 	// Enable or disable scrollbars for the element we represent, preparing it for the first round of layouting, according to our properties.
 	void ResetScrollbars(const Box& box);
 
@@ -56,6 +54,8 @@ public:
 	ContainerBox* GetParent() { return parent_container; }
 	Element* GetElement() { return element; }
 
+	bool IsScrollContainer() const;
+
 	// Returns true if this box acts as a containing block for absolutely positioned descendants.
 	bool IsAbsolutePositioningContainingBlock() const { return is_absolute_positioning_containing_block; }
 

+ 5 - 0
Source/Core/Layout/LayoutDetails.h

@@ -119,6 +119,11 @@ public:
 
 	static String GetDebugElementName(Element* element);
 
+	static bool IsScrollContainer(Style::Overflow overflow_x, Style::Overflow overflow_y)
+	{
+		return overflow_x != Style::Overflow::Visible || overflow_y != Style::Overflow::Visible;
+	}
+
 private:
 	/// Calculates and returns the content size for replaced elements.
 	static Vector2f CalculateSizeForReplacedElement(Vector2f specified_content_size, Vector2f min_size, Vector2f max_size, Vector2f intrinsic_size,