]> git.decadent.org.uk Git - videolink.git/blob - style_sheets.cpp
Changed set_browser_preferences to use the "user" branch rather than the "default...
[videolink.git] / style_sheets.cpp
1 // Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #include "style_sheets.hpp"
5
6 #include <nsContentCID.h>
7 #include <nsICSSLoader.h>
8 #include <nsICSSStyleSheet.h>
9 #include <nsIPresShell.h>
10 #if MOZ_VERSION_MAJOR > 1 || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8)
11 #   include <nsServiceManagerUtils.h>
12 #else
13 #   include <nsIServiceManagerUtils.h>
14 #endif
15 #include <nsIURI.h>
16 #include <nsNetUtil.h>
17
18 #include "xpcom_support.hpp"
19
20 using xpcom_support::check;
21
22 // Load a CSS from an (absolute) URI.
23 // TODO: Support loading from an absolute, or better, relative filename.
24 already_AddRefed<nsIStyleSheet> load_css(const char * uri)
25 {
26     nsCOMPtr<nsICSSLoader> css_loader;
27     static const nsCID css_loader_cid = NS_CSS_LOADER_CID;
28     check(CallGetService<nsICSSLoader>(css_loader_cid,
29                                        getter_AddRefs(css_loader)));
30
31     nsCOMPtr<nsIURI> style_sheet_uri;
32     check(NS_NewURI(getter_AddRefs(style_sheet_uri), nsCString(uri)));
33
34     nsICSSStyleSheet * style_sheet;
35     check(css_loader->LoadAgentSheet(style_sheet_uri, &style_sheet));
36     return style_sheet;
37 }
38
39 // Apply a style-sheet to a given presentation shell as the top-priority
40 // agent style-sheet and disable the preferences-derived style rules.
41 void apply_style_sheet(nsIStyleSheet * style_sheet, nsIPresShell * pres_shell)
42 {
43     nsCOMArray<nsIStyleSheet> style_sheets;
44     check(pres_shell->GetAgentStyleSheets(style_sheets));
45     check(style_sheets.AppendObject(style_sheet));
46     check(pres_shell->SetAgentStyleSheets(style_sheets));
47
48     // FIXME: We need to find an alternative that works in Mozilla 1.8.
49 #   if MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR < 8
50         check(pres_shell->EnablePrefStyleRules(false));
51 #   endif
52
53     // Update the display
54 #   if MOZ_VERSION_MAJOR > 1                              \
55     || (MOZ_VERSION_MAJOR == 1 && MOZ_VERSION_MINOR >= 8)
56         pres_shell->ReconstructStyleData();
57         check(pres_shell->FlushPendingNotifications(Flush_Display));
58 #   else
59         check(pres_shell->ReconstructStyleData());
60         check(pres_shell->FlushPendingNotifications(true));
61 #   endif
62 }