1 module webkit2.ColorChooserRequest; 2 3 private import gdk.RGBA; 4 private import glib.MemorySlice; 5 private import gobject.ObjectG; 6 private import gobject.Signals; 7 private import std.algorithm; 8 private import webkit2.c.functions; 9 public import webkit2.c.types; 10 11 12 /** 13 * Whenever the user interacts with an <input type='color' /> 14 * HTML element, WebKit will need to show a dialog to choose a color. For that 15 * to happen in a general way, instead of just opening a #GtkColorChooser 16 * (which might be not desirable in some cases, which could prefer to use their 17 * own color chooser dialog), WebKit will fire the 18 * #WebKitWebView::run-color-chooser signal with a #WebKitColorChooserRequest 19 * object, which will allow the client application to specify the color to be 20 * selected, to inspect the details of the request (e.g. to get initial color) 21 * and to cancel the request, in case nothing was selected. 22 * 23 * In case the client application does not wish to handle this signal, 24 * WebKit will provide a default handler which will asynchronously run 25 * a regular #GtkColorChooserDialog for the user to interact with. 26 */ 27 public class ColorChooserRequest : ObjectG 28 { 29 /** the main Gtk struct */ 30 protected WebKitColorChooserRequest* webKitColorChooserRequest; 31 32 /** Get the main Gtk struct */ 33 public WebKitColorChooserRequest* getColorChooserRequestStruct(bool transferOwnership = false) 34 { 35 if (transferOwnership) 36 ownedRef = false; 37 return webKitColorChooserRequest; 38 } 39 40 /** the main Gtk struct as a void* */ 41 protected override void* getStruct() 42 { 43 return cast(void*)webKitColorChooserRequest; 44 } 45 46 /** 47 * Sets our main struct and passes it to the parent class. 48 */ 49 public this (WebKitColorChooserRequest* webKitColorChooserRequest, bool ownedRef = false) 50 { 51 this.webKitColorChooserRequest = webKitColorChooserRequest; 52 super(cast(GObject*)webKitColorChooserRequest, ownedRef); 53 } 54 55 56 /** */ 57 public static GType getType() 58 { 59 return webkit_color_chooser_request_get_type(); 60 } 61 62 /** 63 * Cancels @request and the input element changes to use the initial color 64 * it has before the request started. 65 * The signal #WebKitColorChooserRequest::finished 66 * is emitted to notify that the request has finished. 67 * 68 * Since: 2.8 69 */ 70 public void cancel() 71 { 72 webkit_color_chooser_request_cancel(webKitColorChooserRequest); 73 } 74 75 /** 76 * Finishes @request and the input element keeps the current value of 77 * #WebKitColorChooserRequest:rgba. 78 * The signal #WebKitColorChooserRequest::finished 79 * is emitted to notify that the request has finished. 80 * 81 * Since: 2.8 82 */ 83 public void finish() 84 { 85 webkit_color_chooser_request_finish(webKitColorChooserRequest); 86 } 87 88 /** 89 * Gets the bounding box of the color input element. 90 * 91 * Params: 92 * rect = a #GdkRectangle to fill in with the element area 93 * 94 * Since: 2.8 95 */ 96 public void getElementRectangle(out GdkRectangle rect) 97 { 98 webkit_color_chooser_request_get_element_rectangle(webKitColorChooserRequest, &rect); 99 } 100 101 /** 102 * Gets the current #GdkRGBA color of @request 103 * 104 * Params: 105 * rgba = a #GdkRGBA to fill in with the current color. 106 * 107 * Since: 2.8 108 */ 109 public void getRgba(out RGBA rgba) 110 { 111 GdkRGBA* outrgba = sliceNew!GdkRGBA(); 112 113 webkit_color_chooser_request_get_rgba(webKitColorChooserRequest, outrgba); 114 115 rgba = ObjectG.getDObject!(RGBA)(outrgba, true); 116 } 117 118 /** 119 * Sets the current #GdkRGBA color of @request 120 * 121 * Params: 122 * rgba = a pointer #GdkRGBA 123 * 124 * Since: 2.8 125 */ 126 public void setRgba(RGBA rgba) 127 { 128 webkit_color_chooser_request_set_rgba(webKitColorChooserRequest, (rgba is null) ? null : rgba.getRGBAStruct()); 129 } 130 131 /** 132 * Emitted when the @request finishes. This signal can be emitted because the 133 * user completed the @request calling webkit_color_chooser_request_finish(), 134 * or cancelled it with webkit_color_chooser_request_cancel() or because the 135 * color input element is removed from the DOM. 136 * 137 * Since: 2.8 138 */ 139 gulong addOnFinished(void delegate(ColorChooserRequest) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 140 { 141 return Signals.connect(this, "finished", dlg, connectFlags ^ ConnectFlags.SWAPPED); 142 } 143 }