X-Git-Url: https://git.decadent.org.uk/gitweb/?p=videolink.git;a=blobdiff_plain;f=style_sheets.cpp;h=1f66810771976c7d89beae43017bfae0247c8831;hp=568c8e8228216a7f067d8c9f350d3030336eee55;hb=07a027ef87333662b3709215025838646ee3d6be;hpb=c5f98ff303d670f72a5d491a5f4e1989d2043219 diff --git a/style_sheets.cpp b/style_sheets.cpp index 568c8e8..1f66810 100644 --- a/style_sheets.cpp +++ b/style_sheets.cpp @@ -4,10 +4,15 @@ #include "style_sheets.hpp" #include -#include -#include -#include -#include +#if MOZ_VERSION_MAJOR > 1 || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8) +# include +# include +#else +# include +# include +# include +# include +#endif #include #include @@ -15,9 +20,34 @@ using xpcom_support::check; -// Load a CSS from an (absolute) URI. -// TODO: Support loading from an absolute, or better, relative filename. -already_AddRefed load_css(const char * uri) +#if MOZ_VERSION_MAJOR > 1 || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8) + +// We just have to load and register a style-sheet as a user +// style-sheet. There is no need to do anything for each page. + +agent_style_sheet_holder init_agent_style_sheet(const char * uri) +{ + nsCOMPtr style_sheet_uri; + check(NS_NewURI(getter_AddRefs(style_sheet_uri), nsCString(uri))); + + nsCOMPtr style_sheet_service; + static const nsCID style_sheet_service_cid = { + // NS_STYLESHEETSERVICE_CID copied from + // layout/base/nsStyleSheetService.cpp + 0xfcca6f83, 0x9f7d, 0x44e4, + {0xa7, 0x4b, 0xb5, 0x94, 0x33, 0xe6, 0xc8, 0xc3} + }; + check(CallGetService( + style_sheet_service_cid, getter_AddRefs(style_sheet_service))); + check(style_sheet_service->LoadAndRegisterSheet( + style_sheet_uri, nsIStyleSheetService::USER_SHEET)); + + return agent_style_sheet_holder(); +} + +#else // Mozilla version < 1.8 + +already_AddRefed init_agent_style_sheet(const char * uri) { nsCOMPtr css_loader; static const nsCID css_loader_cid = NS_CSS_LOADER_CID; @@ -34,7 +64,8 @@ already_AddRefed load_css(const char * uri) // Apply a style-sheet to a given presentation shell as the top-priority // agent style-sheet and disable the preferences-derived style rules. -void apply_style_sheet(nsIStyleSheet * style_sheet, nsIPresShell * pres_shell) +void apply_agent_style_sheet(nsIStyleSheet * style_sheet, + nsIPresShell * pres_shell) { nsCOMArray style_sheets; check(pres_shell->GetAgentStyleSheets(style_sheets)); @@ -48,3 +79,4 @@ void apply_style_sheet(nsIStyleSheet * style_sheet, nsIPresShell * pres_shell) check(pres_shell->FlushPendingNotifications(true)); } +#endif // Mozilla version >=/< 1.8