]> git.decadent.org.uk Git - videolink.git/blob - style_sheets.cpp
Renamed various types to fit lower_case_with_underscores convention.
[videolink.git] / style_sheets.cpp
1 // Copyright 2005 Ben Hutchings <ben@decadentplace.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 #include <nsIServiceManagerUtils.h>
11 #include <nsIURI.h>
12 #include <nsNetUtil.h>
13
14 #include "xpcom_support.hpp"
15
16 using xpcom_support::check;
17
18 // Load a CSS from an (absolute) URI.
19 // TODO: Support loading from an absolute, or better, relative filename.
20 already_AddRefed<nsIStyleSheet> load_css(const char * uri)
21 {
22     nsCOMPtr<nsICSSLoader> css_loader;
23     static const nsCID css_loader_cid = NS_CSS_LOADER_CID;
24     check(CallGetService<nsICSSLoader>(css_loader_cid,
25                                        getter_AddRefs(css_loader)));
26
27     nsCOMPtr<nsIURI> style_sheet_uri;
28     check(NS_NewURI(getter_AddRefs(style_sheet_uri), nsCString(uri)));
29
30     nsICSSStyleSheet * style_sheet;
31     check(css_loader->LoadAgentSheet(style_sheet_uri, &style_sheet));
32     return style_sheet;
33 }
34
35 // Apply a style-sheet to a given presentation shell as the top-priority
36 // agent style-sheet and disable the preferences-derived style rules.
37 void apply_style_sheet(nsIStyleSheet * style_sheet, nsIPresShell * pres_shell)
38 {
39     nsCOMArray<nsIStyleSheet> style_sheets;
40     check(pres_shell->GetAgentStyleSheets(style_sheets));
41     check(style_sheets.InsertObjectAt(style_sheet, 0));
42     check(pres_shell->SetAgentStyleSheets(style_sheets));
43
44     check(pres_shell->EnablePrefStyleRules(false));
45
46     // Update the display
47     check(pres_shell->ReconstructStyleData());
48     check(pres_shell->FlushPendingNotifications(true));
49 }
50