From: Ben Hutchings Date: Sat, 14 Oct 2006 00:52:28 +0000 (+0000) Subject: Changed style-sheet application in Mozila/XULRunner 1.8 to override built-in preferen... X-Git-Tag: 0.10~4 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=095c46b0de5edd5ae14b4e311d54c723eb73e11f;p=videolink.git Changed style-sheet application in Mozila/XULRunner 1.8 to override built-in preferences, fixing link colours. --- diff --git a/style_sheets.cpp b/style_sheets.cpp index 9c59982..1f66810 100644 --- a/style_sheets.cpp +++ b/style_sheets.cpp @@ -4,12 +4,13 @@ #include "style_sheets.hpp" #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 @@ -19,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; @@ -38,25 +64,19 @@ 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)); - check(style_sheets.AppendObject(style_sheet)); + check(style_sheets.InsertObjectAt(style_sheet, 0)); check(pres_shell->SetAgentStyleSheets(style_sheets)); - // FIXME: We need to find an alternative that works in Mozilla 1.8. -# if MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR < 8 - check(pres_shell->EnablePrefStyleRules(false)); -# endif + check(pres_shell->EnablePrefStyleRules(false)); // Update the display -# if MOZ_VERSION_MAJOR > 1 \ - || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8) - pres_shell->ReconstructStyleData(); - check(pres_shell->FlushPendingNotifications(Flush_Display)); -# else - check(pres_shell->ReconstructStyleData()); - check(pres_shell->FlushPendingNotifications(true)); -# endif + check(pres_shell->ReconstructStyleData()); + check(pres_shell->FlushPendingNotifications(true)); } + +#endif // Mozilla version >=/< 1.8 diff --git a/style_sheets.hpp b/style_sheets.hpp index bb39b22..ef4aef3 100644 --- a/style_sheets.hpp +++ b/style_sheets.hpp @@ -9,12 +9,29 @@ class nsIPresShell; -// Load a CSS from an (absolute) URI. -// TODO: Support loading from an absolute, or better, relative filename. -already_AddRefed load_css(const char * uri); +// These functions load and apply a style-sheet as necessary, +// overriding the built-in "preferences". + +// init_agent_style_sheet() must be called once during startup +// apply_agent_style_sheet() must be called for each page + +#if MOZ_VERSION_MAJOR > 1 || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8) + +struct agent_style_sheet_holder {}; + +// Load agent style sheet from an (absolute) URI, and register it if +// possible. +agent_style_sheet_holder init_agent_style_sheet(const char * uri); +inline void apply_agent_style_sheet(agent_style_sheet_holder, nsIPresShell *) +{} + +#else + +typedef nsCOMPtr agent_style_sheet_holder; +already_AddRefed init_agent_style_sheet(const char * uri); +void apply_agent_style_sheet(nsIStyleSheet *, nsIPresShell *); + +#endif -// 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 *, nsIPresShell *); #endif // !INC_STYLESHEETS_HPP diff --git a/videolink.cpp b/videolink.cpp index 59956c7..8ab5266 100644 --- a/videolink.cpp +++ b/videolink.cpp @@ -194,7 +194,7 @@ namespace std::string output_dir_; mpeg_encoder encoder_; browser_widget browser_widget_; - nsCOMPtr stylesheet_; + agent_style_sheet_holder style_sheet_; dvd_contents contents_; typedef std::map resource_map_type; @@ -219,7 +219,8 @@ namespace : frame_params_(frame_params), output_dir_(output_dir), encoder_(encoder), - stylesheet_(load_css("file://" VIDEOLINK_SHARE_DIR "/videolink.css")), + style_sheet_(init_agent_style_sheet( + "file://"VIDEOLINK_SHARE_DIR"/videolink.css")), pending_window_update_(false), pending_req_count_(0), have_tweaked_page_(false), @@ -440,7 +441,7 @@ namespace // disable scrollbars. if (!have_tweaked_page_) { - apply_style_sheet(stylesheet_, pres_shell); + apply_agent_style_sheet(style_sheet_, pres_shell); // This actually only needs to be done once. nsCOMPtr dom_bar_prop; @@ -874,12 +875,6 @@ namespace check(pref_branch->SetBoolPref( "layout.fire_onload_after_image_background_loads", true)); - - // Turn off link underlining. This is also set in the agent - // stylesheet, but seems to be overridden by preferences in - // Mozilla 1.8. - check(pref_branch->SetBoolPref("browser.underline_anchors", - false)); # endif // Set display resolution. With standard-definition video we