1 module webkit2.UserStyleSheet; 2 3 private import glib.ConstructionException; 4 private import glib.Str; 5 private import gobject.ObjectG; 6 private import webkit2.c.functions; 7 public import webkit2.c.types; 8 9 10 /** */ 11 public class UserStyleSheet 12 { 13 /** the main Gtk struct */ 14 protected WebKitUserStyleSheet* webKitUserStyleSheet; 15 protected bool ownedRef; 16 17 /** Get the main Gtk struct */ 18 public WebKitUserStyleSheet* getUserStyleSheetStruct(bool transferOwnership = false) 19 { 20 if (transferOwnership) 21 ownedRef = false; 22 return webKitUserStyleSheet; 23 } 24 25 /** the main Gtk struct as a void* */ 26 protected void* getStruct() 27 { 28 return cast(void*)webKitUserStyleSheet; 29 } 30 31 /** 32 * Sets our main struct and passes it to the parent class. 33 */ 34 public this (WebKitUserStyleSheet* webKitUserStyleSheet, bool ownedRef = false) 35 { 36 this.webKitUserStyleSheet = webKitUserStyleSheet; 37 this.ownedRef = ownedRef; 38 } 39 40 ~this () 41 { 42 if ( ownedRef ) 43 webkit_user_style_sheet_unref(webKitUserStyleSheet); 44 } 45 46 47 /** */ 48 public static GType getType() 49 { 50 return webkit_user_style_sheet_get_type(); 51 } 52 53 /** 54 * Creates a new user style sheet. Style sheets can be applied to some URIs 55 * only by passing non-null values for @allow_list or @block_list. Passing a 56 * %NULL allow_list implies that all URIs are on the allow_list. The style 57 * sheet is applied if an URI matches the allow_list and not the block_list. 58 * URI patterns must be of the form `[protocol]://[host]/[path]`, where the 59 * *host* and *path* components can contain the wildcard character (`*`) to 60 * represent zero or more other characters. 61 * 62 * Params: 63 * source = Source code of the user style sheet. 64 * injectedFrames = A #WebKitUserContentInjectedFrames value 65 * level = A #WebKitUserStyleLevel 66 * allowList = An allow_list of URI patterns or %NULL 67 * blockList = A block_list of URI patterns or %NULL 68 * 69 * Returns: A new #WebKitUserStyleSheet 70 * 71 * Since: 2.6 72 * 73 * Throws: ConstructionException GTK+ fails to create the object. 74 */ 75 public this(string source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserStyleLevel level, string[] allowList, string[] blockList) 76 { 77 auto __p = webkit_user_style_sheet_new(Str.toStringz(source), injectedFrames, level, Str.toStringzArray(allowList), Str.toStringzArray(blockList)); 78 79 if(__p is null) 80 { 81 throw new ConstructionException("null returned by new"); 82 } 83 84 this(cast(WebKitUserStyleSheet*) __p); 85 } 86 87 /** 88 * Creates a new user style sheet for script world with name @world_name. 89 * See webkit_user_style_sheet_new() for a full description. 90 * 91 * Params: 92 * source = Source code of the user style sheet. 93 * injectedFrames = A #WebKitUserContentInjectedFrames value 94 * level = A #WebKitUserStyleLevel 95 * worldName = the name of a #WebKitScriptWorld 96 * allowList = An allow_list of URI patterns or %NULL 97 * blockList = A block_list of URI patterns or %NULL 98 * 99 * Returns: A new #WebKitUserStyleSheet 100 * 101 * Since: 2.22 102 * 103 * Throws: ConstructionException GTK+ fails to create the object. 104 */ 105 public this(string source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserStyleLevel level, string worldName, string[] allowList, string[] blockList) 106 { 107 auto __p = webkit_user_style_sheet_new_for_world(Str.toStringz(source), injectedFrames, level, Str.toStringz(worldName), Str.toStringzArray(allowList), Str.toStringzArray(blockList)); 108 109 if(__p is null) 110 { 111 throw new ConstructionException("null returned by new_for_world"); 112 } 113 114 this(cast(WebKitUserStyleSheet*) __p); 115 } 116 117 alias doref = ref_; 118 /** 119 * Atomically increments the reference count of @user_style_sheet by one. 120 * This function is MT-safe and may be called from any thread. 121 * 122 * Returns: The passed #WebKitUserStyleSheet 123 * 124 * Since: 2.6 125 */ 126 public UserStyleSheet ref_() 127 { 128 auto __p = webkit_user_style_sheet_ref(webKitUserStyleSheet); 129 130 if(__p is null) 131 { 132 return null; 133 } 134 135 return ObjectG.getDObject!(UserStyleSheet)(cast(WebKitUserStyleSheet*) __p, true); 136 } 137 138 /** 139 * Atomically decrements the reference count of @user_style_sheet by one. 140 * If the reference count drops to 0, all memory allocated by 141 * #WebKitUserStyleSheet is released. This function is MT-safe and may be 142 * called from any thread. 143 * 144 * Since: 2.6 145 */ 146 public void unref() 147 { 148 webkit_user_style_sheet_unref(webKitUserStyleSheet); 149 } 150 }