|
|
@@ -96,28 +96,45 @@ void ElementDocument::ProcessHeader(const DocumentHeader* document_header)
|
|
|
// If a style-sheet (or sheets) has been specified for this element, then we load them and set the combined sheet
|
|
|
// on the element; all of its children will inherit it by default.
|
|
|
SharedPtr<StyleSheet> new_style_sheet;
|
|
|
- if (header.rcss_external.size() > 0)
|
|
|
- new_style_sheet = StyleSheetFactory::GetStyleSheet(header.rcss_external);
|
|
|
|
|
|
// Combine any inline sheets.
|
|
|
- for (size_t i = 0; i < header.rcss_inline.size(); i++)
|
|
|
+ for (const DocumentHeader::Resource& rcss : header.rcss)
|
|
|
{
|
|
|
- UniquePtr<StyleSheet> inline_sheet = MakeUnique<StyleSheet>();
|
|
|
- auto stream = MakeUnique<StreamMemory>((const byte*)header.rcss_inline[i].c_str(), header.rcss_inline[i].size());
|
|
|
- stream->SetSourceURL(document_header->source);
|
|
|
+ if (rcss.is_inline)
|
|
|
+ {
|
|
|
+ UniquePtr<StyleSheet> inline_sheet = MakeUnique<StyleSheet>();
|
|
|
+ auto stream = MakeUnique<StreamMemory>((const byte*)rcss.content.c_str(), rcss.content.size());
|
|
|
+ stream->SetSourceURL(rcss.path);
|
|
|
+
|
|
|
+ if (inline_sheet->LoadStyleSheet(stream.get(), rcss.line))
|
|
|
+ {
|
|
|
+ if (new_style_sheet)
|
|
|
+ {
|
|
|
+ SharedPtr<StyleSheet> combined_sheet = new_style_sheet->CombineStyleSheet(*inline_sheet);
|
|
|
+ new_style_sheet = combined_sheet;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ new_style_sheet = std::move(inline_sheet);
|
|
|
+ }
|
|
|
|
|
|
- if (inline_sheet->LoadStyleSheet(stream.get(), header.rcss_inline_line_numbers[i]))
|
|
|
+ stream.reset();
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- if (new_style_sheet)
|
|
|
+ SharedPtr<StyleSheet> sub_sheet = StyleSheetFactory::GetStyleSheet(rcss.path);
|
|
|
+ if (sub_sheet)
|
|
|
{
|
|
|
- SharedPtr<StyleSheet> combined_sheet = new_style_sheet->CombineStyleSheet(*inline_sheet);
|
|
|
- new_style_sheet = combined_sheet;
|
|
|
+ if (new_style_sheet)
|
|
|
+ {
|
|
|
+ SharedPtr<StyleSheet> combined_sheet = new_style_sheet->CombineStyleSheet(*sub_sheet);
|
|
|
+ new_style_sheet = std::move(combined_sheet);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ new_style_sheet = sub_sheet;
|
|
|
}
|
|
|
else
|
|
|
- new_style_sheet = std::move(inline_sheet);
|
|
|
+ Log::Message(Log::LT_ERROR, "Failed to load style sheet %s.", rcss.path.c_str());
|
|
|
}
|
|
|
-
|
|
|
- stream.reset();
|
|
|
}
|
|
|
|
|
|
// If a style sheet is available, set it on the document and release it.
|
|
|
@@ -126,19 +143,17 @@ void ElementDocument::ProcessHeader(const DocumentHeader* document_header)
|
|
|
SetStyleSheet(std::move(new_style_sheet));
|
|
|
}
|
|
|
|
|
|
- // Load external scripts.
|
|
|
- for (size_t i = 0; i < header.scripts_external.size(); i++)
|
|
|
+ // Load scripts.
|
|
|
+ for (const DocumentHeader::Resource& script : header.scripts)
|
|
|
{
|
|
|
- auto stream = MakeUnique<StreamFile>();
|
|
|
- if (stream->Open(header.scripts_external[i]))
|
|
|
- LoadScript(stream.get(), header.scripts_external[i]);
|
|
|
- }
|
|
|
-
|
|
|
- // Load internal scripts.
|
|
|
- for (size_t i = 0; i < header.scripts_inline.size(); i++)
|
|
|
- {
|
|
|
- auto stream = MakeUnique<StreamMemory>((const byte*) header.scripts_inline[i].c_str(), header.scripts_inline[i].size());
|
|
|
- LoadScript(stream.get(), "");
|
|
|
+ if (script.is_inline)
|
|
|
+ {
|
|
|
+ LoadInlineScript(script.content, script.path, script.line);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LoadExternalScript(script.path);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Hide this document.
|
|
|
@@ -341,11 +356,18 @@ bool ElementDocument::IsModal() const
|
|
|
return modal && IsVisible();
|
|
|
}
|
|
|
|
|
|
-// Default load script implementation
|
|
|
-void ElementDocument::LoadScript(Stream* RMLUI_UNUSED_PARAMETER(stream), const String& RMLUI_UNUSED_PARAMETER(source_name))
|
|
|
+// Default load inline script implementation
|
|
|
+void ElementDocument::LoadInlineScript(const String& RMLUI_UNUSED_PARAMETER(content), const String& RMLUI_UNUSED_PARAMETER(source_path), int RMLUI_UNUSED_PARAMETER(line))
|
|
|
+{
|
|
|
+ RMLUI_UNUSED(content);
|
|
|
+ RMLUI_UNUSED(source_path);
|
|
|
+ RMLUI_UNUSED(line);
|
|
|
+}
|
|
|
+
|
|
|
+// Default load external script implementation
|
|
|
+void ElementDocument::LoadExternalScript(const String& RMLUI_UNUSED_PARAMETER(source_path))
|
|
|
{
|
|
|
- RMLUI_UNUSED(stream);
|
|
|
- RMLUI_UNUSED(source_name);
|
|
|
+ RMLUI_UNUSED(source_path);
|
|
|
}
|
|
|
|
|
|
// Updates the document, including its layout
|