X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=style_sheets.cpp;fp=style_sheets.cpp;h=576780055d514d5b2575c607329107628fa50c93;hb=0acb5f1329d294faf42e247f8c2daf68d82150f6;hp=0000000000000000000000000000000000000000;hpb=1b6026c7baa122b99011f760857b80b7f253dfbb;p=videolink.git diff --git a/style_sheets.cpp b/style_sheets.cpp new file mode 100644 index 0000000..5767800 --- /dev/null +++ b/style_sheets.cpp @@ -0,0 +1,50 @@ +// Copyright 2005 Ben Hutchings . +// See the file "COPYING" for licence details. + +#include "style_sheets.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include "xpcom_support.hpp" + +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) +{ + nsCOMPtr css_loader; + static const nsCID css_loader_cid = NS_CSS_LOADER_CID; + check(CallGetService(css_loader_cid, + getter_AddRefs(css_loader))); + + nsCOMPtr style_sheet_uri; + check(NS_NewURI(getter_AddRefs(style_sheet_uri), nsCString(uri))); + + nsICSSStyleSheet * style_sheet; + check(css_loader->LoadAgentSheet(style_sheet_uri, &style_sheet)); + return style_sheet; +} + +// 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) +{ + nsCOMArray style_sheets; + check(pres_shell->GetAgentStyleSheets(style_sheets)); + check(style_sheets.InsertObjectAt(style_sheet, 0)); + check(pres_shell->SetAgentStyleSheets(style_sheets)); + + check(pres_shell->EnablePrefStyleRules(false)); + + // Update the display + check(pres_shell->ReconstructStyleData()); + check(pres_shell->FlushPendingNotifications(true)); +} +