Bug 17626 - Programatically set background color and 16-bit alpha on WebKit GTK
Summary: Programatically set background color and 16-bit alpha on WebKit GTK
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2008-02-29 21:58 PST by Sean Egan
Modified: 2014-04-08 17:45 PDT (History)
4 users (show)

See Also:


Attachments
Patch to set background color and alpha (10.55 KB, patch)
2008-02-29 21:59 PST, Sean Egan
darin: review-
Details | Formatted Diff | Diff
New version of patch (9.81 KB, patch)
2008-03-10 21:46 PDT, Sean Egan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Egan 2008-02-29 21:58:12 PST
The OSX API allows you to set a background NSColor, which represents and RGBA value. The GTK+ analog to this is GdkColor, which only supports RGB. I've modeled this interface after GtkColorSelection which has separate, but similar, functions and properties for GdkColors and a separate guint16 alpha value.

I've kept the set_transparent/get_transparent API for backward compatibility, but suspect they should be deprecated.


I also fixed some compiler warnings.
Comment 1 Sean Egan 2008-02-29 21:59:22 PST
Created attachment 19469 [details]
Patch to set background color and alpha
Comment 2 Alp Toker 2008-03-01 12:48:11 PST
(In reply to comment #0)
> The OSX API allows you to set a background NSColor, which represents and RGBA
> value. The GTK+ analog to this is GdkColor, which only supports RGB. I've
> modeled this interface after GtkColorSelection which has separate, but similar,
> functions and properties for GdkColors and a separate guint16 alpha value.
> 
> I've kept the set_transparent/get_transparent API for backward compatibility,
> but suspect they should be deprecated.

set_transparent/get_transparent() is actually based directly on the drawsBackground from the Mac API (there might still be a case for removing it), but you are right that setting a background color is also a useful feature present on Mac.

I'll need to compare the proposed implementation to the one in Mac since Mac's was slightly more compilicated IIRC.

Out of curiosity, is the background color/alpha setting useful in apps (guessing this is for pidgin)?
Comment 3 Sean Egan 2008-03-01 13:00:33 PST
(In reply to comment #2)

> set_transparent/get_transparent() is actually based directly on the
> drawsBackground from the Mac API (there might still be a case for removing it),
> but you are right that setting a background color is also a useful feature
> present on Mac.

Oh, ok. I misundersood what 'setDrawsBackground' does, but it looks like maybe it's supposed to be deprecated? Adium says:

        if ([self respondsToSelector:@selector(setBackgroundColor:)]) {
                //As of Safari 3.0, we must call setBackgroundColor: to make the webview transparent
                [self setBackgroundColor:(flag ? [NSColor clearColor] : [NSColor whiteColor])];

        } else {
                [self setDrawsBackground:!flag];
        }

> Out of curiosity, is the background color/alpha setting useful in apps
> (guessing this is for pidgin)?
 
Yeah! http://pidgin.im/~seanegan/webkit11.png
Comment 4 Darin Adler 2008-03-02 19:08:54 PST
Comment on attachment 19469 [details]
Patch to set background color and alpha

+        g_value_set_uint(value, webkit_web_view_get_background_alpha(webView));
     default:

Missing a break here. I'm going to set review- because of that. Otherwise looks pretty good, but I'm not a GTK platform expert.

-        gboolean transparent;
+	GdkColor bg_color;
+	guint16 bg_alpha;
+	gboolean bg_color_set;

This indentation in the new code is done with tabs, and there's also a tab in the ChangeLog entry. We can't check tabs into our repository, so please try to avoid tabs while writing the patch to help the person committing it.
Comment 5 Sean Egan 2008-03-10 21:46:51 PDT
Created attachment 19655 [details]
New version of patch
Comment 6 Holger Freyther 2008-03-12 02:24:24 PDT
(In reply to comment #5)
> Created an attachment (id=19655) [edit]
> New version of patch
> 

+    case PROP_BG_ALPHA:
+        webkit_web_view_set_background_alpha(webView, g_value_get_uint(value));
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);

another missing break?
Comment 7 Holger Freyther 2008-03-12 02:27:25 PDT
Some minor coding style issues, the int cast should probably be a different patch but if alp is happy with the API one can sort this out when landing the patch.

But please try to follow the Coding Style it makes it more easy for us to land patches.
Comment 8 Holger Freyther 2008-04-30 00:34:14 PDT
Okay, I will merge this.
Comment 9 Holger Freyther 2008-04-30 02:11:09 PDT
Comment on attachment 19655 [details]
New version of patch

Okay.
Comment 10 Holger Freyther 2008-04-30 02:14:03 PDT
Okay, I landed the patch in r32723 but there are a couple of things:
   - I added the missing break
   - I removed reading the bg property (also removed the method) because bg_color was unitialized or contained old data. e.g. a call to set_bg_color(NULL) and then asking for the color would still return the old color.
   - You want to set the transparency for the view() in WebKit/gtk/WebCoreSupport/FrameLoaderClient as well.

Please send an updated patch, leaving the bug open due the above issues. Thank you.
Comment 11 Darin Adler 2008-06-08 12:43:59 PDT
Comment on attachment 19655 [details]
New version of patch

Clearing the review flag since this patch was landed.
Comment 12 Martin Robinson 2014-04-08 17:45:37 PDT
WebKit1GTK+ has been removed.