Пример #1
0
void ElementInfo::BuildPropertiesRML(Core::String& property_rml, const NamedPropertyList& properties)
{
	Core::String last_source;
	int last_source_line = -1;

	for (size_t i = 0; i < properties.size(); ++i)
	{
		if (i == 0 ||
			last_source != properties[i].second->source ||
			last_source_line != properties[i].second->source_line_number)
		{
			last_source = properties[i].second->source;
			last_source_line = properties[i].second->source_line_number;

			property_rml.Append("<h4>");

			if (last_source.Empty() &&
				last_source_line == 0)
				property_rml.Append("<em>inline</em>");
			else
				property_rml.Append(Core::String(last_source.Length() + 32, "<em>%s</em>: %d", last_source.CString(), last_source_line));

			property_rml.Append("</h4>");
		}

		BuildPropertyRML(property_rml, properties[i].first, properties[i].second);
	}
}
Пример #2
0
void ElementLog::OnRender()
{
	Core::ElementDocument::OnRender();

	if (dirty_logs)
	{
		// Set the log content:
		Core::String messages;
		if (message_content)
		{
			unsigned int log_pointers[Core::Log::LT_MAX];
			for (int i = 0; i < Core::Log::LT_MAX; i++)
				log_pointers[i] = 0;
			int next_type = FindNextEarliestLogType(log_pointers);
			int num_messages = 0;
			while (next_type != -1 && num_messages < MAX_LOG_MESSAGES)
			{
				messages.Append(Core::String(128, "<div class=\"log-entry\"><div class=\"icon %s\">%s</div><p class=\"message\">", log_types[next_type].class_name.CString(), log_types[next_type].alert_contents.CString()));
				messages.Append(log_types[next_type].log_messages[log_pointers[next_type]].message);
				messages.Append("</p></div>");
				
				log_pointers[next_type]++;
				next_type = FindNextEarliestLogType(log_pointers);
				num_messages++;
			}

			if (message_content->HasChildNodes())
			{
				float last_element_top = message_content->GetLastChild()->GetAbsoluteTop();
				auto_scroll = message_content->GetAbsoluteTop() + message_content->GetAbsoluteTop() > last_element_top;
			}
			else
				auto_scroll = true;

			message_content->SetInnerRML(messages);		

			dirty_logs = false;
		}
	}
}
Пример #3
0
void ElementInfo::BuildElementPropertiesRML(Core::String& property_rml, Core::Element* element, Core::Element* primary_element)
{
	NamedPropertyMap property_map;

	int property_index = 0;
	Core::String property_name;
	Core::PseudoClassList property_pseudo_classes;
	const Core::Property* property;

	while (element->IterateProperties(property_index, property_pseudo_classes, property_name, property))
	{
		// Check that this property isn't overridden or just not inherited.
		if (primary_element->GetProperty(property_name) != property)
			continue;

		NamedPropertyMap::iterator i = property_map.find(property_pseudo_classes);
		if (i == property_map.end())
			property_map[property_pseudo_classes] = NamedPropertyList(1, NamedProperty(property_name, property));
		else
		{
			// Find a place in this list of properties to insert the new one.
			NamedPropertyList& properties = (*i).second;
			NamedPropertyList::iterator insert_iterator = properties.begin();
			while (insert_iterator != properties.end())
			{
				int source_cmp = strcasecmp((*insert_iterator).second->source.CString(), property->source.CString());
				if (source_cmp > 0 ||
					(source_cmp == 0 && (*insert_iterator).second->source_line_number >= property->source_line_number))
					break;

				++insert_iterator;
			}

			(*i).second.insert(insert_iterator, NamedProperty(property_name, property));
		}
	}

	if (!property_map.empty())
	{
		// Print the 'inherited from ...' header if we're not the primary element.
		if (element != primary_element)
			property_rml += Core::String(element->GetTagName().Length() + 32, "<h3>inherited from %s</h3>", element->GetTagName().CString());

		NamedPropertyMap::iterator base_properties = property_map.find(Core::PseudoClassList());
		if (base_properties != property_map.end())
			BuildPropertiesRML(property_rml, (*base_properties).second);

		for (NamedPropertyMap::iterator i = property_map.begin(); i != property_map.end(); ++i)
		{
			// Skip the base property list, we've already printed it.
			if (i == base_properties)
				continue;

			// Print the pseudo-class header.
			property_rml.Append("<h3>");

			for (Core::PseudoClassList::const_iterator j = (*i).first.begin(); j != (*i).first.end(); ++j)
			{
				property_rml.Append(" :");
				property_rml.Append(*j);
			}

			property_rml.Append("</h3>");

			BuildPropertiesRML(property_rml, (*i).second);
		}
	}

	if (element->GetParentNode() != NULL)
		BuildElementPropertiesRML(property_rml, element->GetParentNode(), primary_element);
}
Пример #4
0
void ElementInfo::UpdateSourceElement()
{
	// Set the title:
	Core::Element* title_content = GetElementById("title-content");
	if (title_content != NULL)
	{
		if (source_element != NULL)
			title_content->SetInnerRML(source_element->GetTagName());
		else
			title_content->SetInnerRML("Element Information");
	}

	// Set the attributes:
	Core::Element* attributes_content = GetElementById("attributes-content");
	if (attributes_content)
	{
		int index = 0;
		Core::String name;
		Core::String value;
		Core::String attributes;

		if (source_element != NULL)
		{
			while (source_element->IterateAttributes(index, name, value))
				attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
		}

		if (attributes.Empty())
		{
			while (attributes_content->HasChildNodes())
				attributes_content->RemoveChild(attributes_content->GetChild(0));
		}
		else
			attributes_content->SetInnerRML(attributes);
	}

	// Set the properties:
	Core::Element* properties_content = GetElementById("properties-content");
	if (properties_content)
	{
		Core::String properties;
		if (source_element != NULL)
			BuildElementPropertiesRML(properties, source_element, source_element);

		if (properties.Empty())
		{
			while (properties_content->HasChildNodes())
				properties_content->RemoveChild(properties_content->GetChild(0));
		}
		else
			properties_content->SetInnerRML(properties);
	}

	// Set the position:
	Core::Element* position_content = GetElementById("position-content");
	if (position_content)
	{
		// left, top, width, height.
		if (source_element != NULL)
		{
			Core::Vector2f element_offset = source_element->GetRelativeOffset(Core::Box::BORDER);
			Core::Vector2f element_size = source_element->GetBox().GetSize(Core::Box::BORDER);

			Core::String positions;
			positions.Append(Core::String(64, "left: <em>%.0fpx</em><br />", element_offset.x));
			positions.Append(Core::String(64, "top: <em>%.0fpx</em><br />", element_offset.y));
			positions.Append(Core::String(64, "width: <em>%.0fpx</em><br />", element_size.x));
			positions.Append(Core::String(64, "height: <em>%.0fpx</em><br />", element_size.y));

			position_content->SetInnerRML(positions);
		}
		else
		{
			while (position_content->HasChildNodes())
				position_content->RemoveChild(position_content->GetFirstChild());
		}
	}

	// Set the ancestors:
	Core::Element* ancestors_content = GetElementById("ancestors-content");
	if (ancestors_content)
	{
		Core::String ancestors;
		Core::Element* element_ancestor = NULL;
		if (source_element != NULL)
			element_ancestor = source_element->GetParentNode();

		int ancestor_depth = 1;
		while (element_ancestor)
		{
			Core::String ancestor_name = element_ancestor->GetTagName();
			const Core::String ancestor_id = element_ancestor->GetId();
			if (!ancestor_id.Empty())
			{
				ancestor_name += "#";
				ancestor_name += ancestor_id;
			}

			ancestors.Append(Core::String(ancestor_name.Length() + 32, "<p id=\"a %d\">%s</p>", ancestor_depth, ancestor_name.CString()));
			element_ancestor = element_ancestor->GetParentNode();
			ancestor_depth++;
		}

		if (ancestors.Empty())
		{
			while (ancestors_content->HasChildNodes())
				ancestors_content->RemoveChild(ancestors_content->GetFirstChild());
		}
		else
			ancestors_content->SetInnerRML(ancestors);
	}

	// Set the children:
	Core::Element* children_content = GetElementById("children-content");
	if (children_content)
	{
		Core::String children;
		if (source_element != NULL)
		{
			for (int i = 0; i < source_element->GetNumChildren(); i++)
			{
				Core::Element* child = source_element->GetChild(i);

				// If this is a debugger document, do not show it.
				if (IsDebuggerElement(child))
					continue;

				Core::String child_name = child->GetTagName();
				const Core::String child_id = child->GetId();
				if (!child_id.Empty())
				{
					child_name += "#";
					child_name += child_id;
				}

				children.Append(Core::String(child_name.Length() + 32, "<p id=\"c %d\">%s</p>", i, child_name.CString()));
			}
		}

		if (children.Empty())
		{
			while (children_content->HasChildNodes())
				children_content->RemoveChild(children_content->GetChild(0));
		}
		else
			children_content->SetInnerRML(children);
	}
}