summaryrefslogtreecommitdiffstats
path: root/abs/extra-testing/community/firefox/mozbug421977.patch
blob: df8371ab3f0d542886e723ec92546deafa7572fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Index: browser/components/shell/src/nsGNOMEShellService.cpp
===================================================================
RCS file: /cvsroot/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp,v
retrieving revision 1.21
diff -d -u -p -U 8 -r1.21 nsGNOMEShellService.cpp
--- browser/components/shell/src/nsGNOMEShellService.cpp	1 Oct 2007 18:25:26 -0000	1.21
+++ browser/components/shell/src/nsGNOMEShellService.cpp	15 Mar 2008 07:08:47 -0000
@@ -58,16 +58,17 @@
 #include "nsIImage.h"
 #include "prprf.h"
 #ifdef MOZ_WIDGET_GTK2
 #include "nsIImageToPixbuf.h"
 #endif
 
 #include <glib.h>
 #include <glib-object.h>
+#include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <limits.h>
 #include <stdlib.h>
 
 struct ProtocolAssociation
 {
   const char *name;
   PRBool essential;
@@ -442,117 +443,56 @@ nsGNOMEShellService::SetDesktopBackgroun
                    EmptyCString());
 
   gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey), filePath);
   gconf->SetBool(NS_LITERAL_CSTRING(kDesktopDrawBGKey), PR_TRUE);
 
   return rv;
 }
 
-// In: pointer to two characters CC
-// Out: parsed color number
-static PRUint8
-HexToNum(char ch)
-{
-  if ('0' <= ch && '9' >= ch)
-    return ch - '0';
-
-  if ('A' <= ch && 'F' >= ch)
-    return ch - 'A';
-
-  if ('a' <= ch && 'f' >= ch)
-    return ch - 'a';
-
-  return 0;
-}
-  
-
-// In: 3 or 6-character RRGGBB hex string
-// Out: component colors
-static PRBool
-HexToRGB(const nsCString& aColorSpec,
-         PRUint8 &aRed,
-         PRUint8 &aGreen,
-         PRUint8 &aBlue)
-{
-  const char *buf = aColorSpec.get();
-
-  if (aColorSpec.Length() == 6) {
-    aRed =    HexToNum(buf[0]) >> 4 |
-              HexToNum(buf[1]);
-    aGreen =  HexToNum(buf[2]) >> 4 |
-              HexToNum(buf[3]);
-    aBlue =   HexToNum(buf[4]) >> 4 |
-              HexToNum(buf[5]);
-    return PR_TRUE;
-  }
-
-  if (aColorSpec.Length() == 3) {
-    aRed = HexToNum(buf[0]);
-    aGreen = HexToNum(buf[1]);
-    aBlue = HexToNum(buf[2]);
-
-    aRed |= aRed >> 4;
-    aGreen |= aGreen >> 4;
-    aBlue |= aBlue >> 4;
-
-    return PR_TRUE;
-  }
-
-  return PR_FALSE;
-}
+#define COLOR_16_TO_8_BIT(_c) ((_c) >> 8)
+#define COLOR_8_TO_16_BIT(_c) ((_c) << 8)
 
 NS_IMETHODIMP
 nsGNOMEShellService::GetDesktopBackgroundColor(PRUint32 *aColor)
 {
   nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
 
   nsCAutoString background;
   gconf->GetString(NS_LITERAL_CSTRING(kDesktopColorKey), background);
 
   if (background.IsEmpty()) {
     *aColor = 0;
     return NS_OK;
   }
 
-  // Chop off the leading '#' character
-  background.Cut(0, 1);
+  GdkColor color;
+  gboolean success = gdk_color_parse(background.get(), &color);
 
-  PRUint8 red, green, blue;
-  if (!HexToRGB(background, red, green, blue))
-      return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
 
-  // The result must be in RGB order with the high 8 bits zero.
-  *aColor = (red << 16 | green << 8  | blue);
+  *aColor = COLOR_16_TO_8_BIT(color.red) << 16 |
+            COLOR_16_TO_8_BIT(color.green) << 8 |
+            COLOR_16_TO_8_BIT(color.blue);
   return NS_OK;
 }
 
-static void
-ColorToHex(PRUint32 aColor, nsCString& aResult)
-{
-  char *buf = aResult.BeginWriting(7);
-  if (!buf)
-    return;
-
-  PRUint8 red = (aColor >> 16);
-  PRUint8 green = (aColor >> 8) & 0xff;
-  PRUint8 blue = aColor & 0xff;
-
-  PR_snprintf(buf, 8, "#%02x%02x%02x", red, green, blue);
-}
-
 NS_IMETHODIMP
 nsGNOMEShellService::SetDesktopBackgroundColor(PRUint32 aColor)
 {
   nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
 
-  nsCString colorString;
-  ColorToHex(aColor, colorString);
+  GdkColor color;
+  color.red = COLOR_8_TO_16_BIT(aColor >> 16);
+  color.green = COLOR_8_TO_16_BIT((aColor >> 8) & 0xff);
+  color.blue = COLOR_8_TO_16_BIT(aColor & 0xff);
 
-  gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), colorString);
+  gchar *colorString = gdk_color_to_string(&color);
+  gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), nsDependentCString(colorString));
+  g_free (colorString);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGNOMEShellService::OpenApplication(PRInt32 aApplication)
 {
   nsCAutoString scheme;