Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: chrome/browser/ui/libgtkui/gtk_util.cc

Issue 2682593006: Gtk3: Bugfixes on several themes (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/libgtkui/native_theme_gtk3.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/libgtkui/gtk_util.h" 5 #include "chrome/browser/ui/libgtkui/gtk_util.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <gdk/gdk.h> 8 #include <gdk/gdk.h>
9 #include <gdk/gdkx.h> 9 #include <gdk/gdkx.h>
10 #include <gtk/gtk.h> 10 #include <gtk/gtk.h>
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 size.width(), 221 size.width(),
222 size.height())), 222 size.height())),
223 cairo_(cairo_create(surface_)) {} 223 cairo_(cairo_create(surface_)) {}
224 224
225 CairoSurface::~CairoSurface() { 225 CairoSurface::~CairoSurface() {
226 cairo_destroy(cairo_); 226 cairo_destroy(cairo_);
227 cairo_surface_destroy(surface_); 227 cairo_surface_destroy(surface_);
228 } 228 }
229 229
230 SkColor CairoSurface::GetAveragePixelValue(bool only_frame_pixels) { 230 SkColor CairoSurface::GetAveragePixelValue(bool only_frame_pixels) {
231 cairo_surface_flush(surface_);
231 int num_samples = 0; 232 int num_samples = 0;
232 long a = 0, r = 0, g = 0, b = 0; 233 long a = 0, r = 0, g = 0, b = 0;
233 SkColor* data = 234 SkColor* data =
234 reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); 235 reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_));
235 int width = cairo_image_surface_get_width(surface_); 236 int width = cairo_image_surface_get_width(surface_);
236 int height = cairo_image_surface_get_height(surface_); 237 int height = cairo_image_surface_get_height(surface_);
238 DCHECK(4 * width == cairo_image_surface_get_stride(surface_));
237 auto accumulate = [&](int x, int y) mutable { 239 auto accumulate = [&](int x, int y) mutable {
238 SkColor color = data[x * width + y]; 240 SkColor color = data[y * width + x];
239 int alpha = SkColorGetA(color); 241 int alpha = SkColorGetA(color);
240 a += alpha; 242 a += alpha;
241 r += alpha * SkColorGetR(color); 243 r += alpha * SkColorGetR(color);
242 g += alpha * SkColorGetG(color); 244 g += alpha * SkColorGetG(color);
243 b += alpha * SkColorGetB(color); 245 b += alpha * SkColorGetB(color);
244 num_samples++; 246 num_samples++;
245 }; 247 };
246 if (width == 1 || height == 1 || !only_frame_pixels) { 248 if (width == 1 || height == 1 || !only_frame_pixels) {
247 // Count every pixel in the surface. 249 // Count every pixel in the surface.
248 for (int x = 0; x < width; x++) 250 for (int x = 0; x < width; x++)
249 for (int y = 0; y < height; y++) 251 for (int y = 0; y < height; y++)
250 accumulate(x, y); 252 accumulate(x, y);
251 } else { 253 } else {
252 // Count the pixels in the top and bottom rows. 254 // Count the pixels in the top and bottom rows.
253 for (int x = 0; x < width; x++) 255 for (int x = 0; x < width; x++)
254 for (int y : {0, height - 1}) 256 for (int y : {0, height - 1})
255 accumulate(x, y); 257 accumulate(x, y);
256 // Count the pixels in the left and right columns. 258 // Count the pixels in the left and right columns.
257 for (int x : {0, width - 1}) 259 for (int x : {0, width - 1})
258 for (int y = 1; y < height - 1; y++) 260 for (int y = 1; y < height - 1; y++)
259 accumulate(x, y); 261 accumulate(x, y);
260 } 262 }
263 if (a == 0)
264 return SK_ColorTRANSPARENT;
261 return SkColorSetARGB(a / num_samples, r / a, g / a, b / a); 265 return SkColorSetARGB(a / num_samples, r / a, g / a, b / a);
262 } 266 }
263 267
264 bool GtkVersionCheck(int major, int minor, int micro) { 268 bool GtkVersionCheck(int major, int minor, int micro) {
265 static int actual_major = gtk_get_major_version(); 269 static int actual_major = gtk_get_major_version();
266 if (actual_major > major) 270 if (actual_major > major)
267 return true; 271 return true;
268 else if (actual_major < major) 272 else if (actual_major < major)
269 return false; 273 return false;
270 274
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 // background color. Only return the border color if there is one. 529 // background color. Only return the border color if there is one.
526 SkColor border = GetBorderColor(css_selector); 530 SkColor border = GetBorderColor(css_selector);
527 if (SkColorGetA(border)) 531 if (SkColorGetA(border))
528 return border; 532 return border;
529 533
530 return GetBgColor(css_selector); 534 return GetBgColor(css_selector);
531 } 535 }
532 #endif 536 #endif
533 537
534 } // namespace libgtkui 538 } // namespace libgtkui
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/libgtkui/native_theme_gtk3.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698