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

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

Issue 2628043002: Gtk3: Render a GtkHeaderBar as the background of the tab strip (Closed)
Patch Set: Guard kFrameTopArea with #if defined(OS_LINUX) && !defined(OS_CHROMEOS) Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/native_theme_gtk3.h" 5 #include "chrome/browser/ui/libgtkui/native_theme_gtk3.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h" 9 #include "chrome/browser/ui/libgtkui/chrome_gtk_frame.h"
10 #include "chrome/browser/ui/libgtkui/chrome_gtk_menu_subclasses.h" 10 #include "chrome/browser/ui/libgtkui/chrome_gtk_menu_subclasses.h"
11 #include "chrome/browser/ui/libgtkui/gtk_util.h" 11 #include "chrome/browser/ui/libgtkui/gtk_util.h"
12 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" 12 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
13 #include "ui/gfx/color_palette.h" 13 #include "ui/gfx/color_palette.h"
14 #include "ui/gfx/color_utils.h" 14 #include "ui/gfx/color_utils.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/skbitmap_operations.h"
16 #include "ui/native_theme/native_theme_dark_aura.h" 17 #include "ui/native_theme/native_theme_dark_aura.h"
17 18
18 namespace libgtkui { 19 namespace libgtkui {
19 20
20 namespace { 21 namespace {
21 22
22 void PaintWidget(SkCanvas* canvas, 23 SkBitmap GetWidgetBitmap(const gfx::Size& size,
23 const gfx::Rect& rect, 24 GtkStyleContext* context) {
24 const char* css_selector,
25 GtkStateFlags state) {
26 SkBitmap bitmap; 25 SkBitmap bitmap;
27 bitmap.allocN32Pixels(rect.width(), rect.height()); 26 bitmap.allocN32Pixels(size.width(), size.height());
28 bitmap.eraseColor(0); 27 bitmap.eraseColor(0);
29 28
30 cairo_surface_t* surface = cairo_image_surface_create_for_data( 29 cairo_surface_t* surface = cairo_image_surface_create_for_data(
31 static_cast<unsigned char*>(bitmap.getAddr(0, 0)), CAIRO_FORMAT_ARGB32, 30 static_cast<unsigned char*>(bitmap.getAddr(0, 0)), CAIRO_FORMAT_ARGB32,
32 rect.width(), rect.height(), 31 size.width(), size.height(),
33 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, rect.width())); 32 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, size.width()));
34 cairo_t* cr = cairo_create(surface); 33 cairo_t* cr = cairo_create(surface);
35 34
36 auto context = GetStyleContextFromCss(css_selector); 35 RenderBackground(size, cr, context);
37 gtk_style_context_set_state(context, state); 36 gtk_render_frame(context, cr, 0, 0, size.width(), size.height());
38
39 gtk_render_background(context, cr, 0, 0, rect.width(), rect.height());
40 gtk_render_frame(context, cr, 0, 0, rect.width(), rect.height());
41 cairo_destroy(cr); 37 cairo_destroy(cr);
42 cairo_surface_destroy(surface); 38 cairo_surface_destroy(surface);
43 canvas->drawBitmap(bitmap, rect.x(), rect.y()); 39 return bitmap;
40 }
41
42 void PaintWidget(SkCanvas* canvas,
43 const gfx::Rect& rect,
44 GtkStyleContext* context) {
45 canvas->drawBitmap(GetWidgetBitmap(rect.size(), context), rect.x(), rect.y());
44 } 46 }
45 47
46 GtkStateFlags StateToStateFlags(NativeThemeGtk3::State state) { 48 GtkStateFlags StateToStateFlags(NativeThemeGtk3::State state) {
47 switch (state) { 49 switch (state) {
48 case NativeThemeGtk3::kDisabled: 50 case NativeThemeGtk3::kDisabled:
49 return GTK_STATE_FLAG_INSENSITIVE; 51 return GTK_STATE_FLAG_INSENSITIVE;
50 case NativeThemeGtk3::kHovered: 52 case NativeThemeGtk3::kHovered:
51 return GTK_STATE_FLAG_PRELIGHT; 53 return GTK_STATE_FLAG_PRELIGHT;
52 case NativeThemeGtk3::kNormal: 54 case NativeThemeGtk3::kNormal:
53 return GTK_STATE_FLAG_NORMAL; 55 return GTK_STATE_FLAG_NORMAL;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 g_type_class_unref(g_type_class_ref(gtk_spinner_get_type())); 328 g_type_class_unref(g_type_class_ref(gtk_spinner_get_type()));
327 g_type_class_unref(g_type_class_ref(gtk_menu_get_type())); 329 g_type_class_unref(g_type_class_ref(gtk_menu_get_type()));
328 g_type_class_unref(g_type_class_ref(gtk_menu_item_get_type())); 330 g_type_class_unref(g_type_class_ref(gtk_menu_item_get_type()));
329 g_type_class_unref(g_type_class_ref(gtk_entry_get_type())); 331 g_type_class_unref(g_type_class_ref(gtk_entry_get_type()));
330 g_type_class_unref(g_type_class_ref(gtk_info_bar_get_type())); 332 g_type_class_unref(g_type_class_ref(gtk_info_bar_get_type()));
331 g_type_class_unref(g_type_class_ref(gtk_tooltip_get_type())); 333 g_type_class_unref(g_type_class_ref(gtk_tooltip_get_type()));
332 g_type_class_unref(g_type_class_ref(gtk_scrollbar_get_type())); 334 g_type_class_unref(g_type_class_ref(gtk_scrollbar_get_type()));
333 g_type_class_unref(g_type_class_ref(gtk_toolbar_get_type())); 335 g_type_class_unref(g_type_class_ref(gtk_toolbar_get_type()));
334 g_type_class_unref(g_type_class_ref(gtk_text_view_get_type())); 336 g_type_class_unref(g_type_class_ref(gtk_text_view_get_type()));
335 g_type_class_unref(g_type_class_ref(gtk_separator_get_type())); 337 g_type_class_unref(g_type_class_ref(gtk_separator_get_type()));
338 g_type_class_unref(g_type_class_ref(gtk_menu_bar_get_type()));
336 339
337 g_signal_connect_after(gtk_settings_get_default(), "notify::gtk-theme-name", 340 g_signal_connect_after(gtk_settings_get_default(), "notify::gtk-theme-name",
338 G_CALLBACK(OnThemeChanged), this); 341 G_CALLBACK(OnThemeChanged), this);
339 } 342 }
340 343
341 // This doesn't actually get called 344 // This doesn't actually get called
342 NativeThemeGtk3::~NativeThemeGtk3() {} 345 NativeThemeGtk3::~NativeThemeGtk3() {}
343 346
344 void NativeThemeGtk3::ResetColorCache() { 347 void NativeThemeGtk3::ResetColorCache() {
345 for (auto& color : color_cache_) 348 for (auto& color : color_cache_)
346 color = base::nullopt; 349 color = base::nullopt;
347 } 350 }
348 351
349 SkColor NativeThemeGtk3::GetSystemColor(ColorId color_id) const { 352 SkColor NativeThemeGtk3::GetSystemColor(ColorId color_id) const {
350 if (color_cache_[color_id]) 353 if (color_cache_[color_id])
351 return color_cache_[color_id].value(); 354 return color_cache_[color_id].value();
352 355
353 SkColor color = SkColorFromColorId(color_id); 356 SkColor color = SkColorFromColorId(color_id);
354 color_cache_[color_id] = color; 357 color_cache_[color_id] = color;
355 return color; 358 return color;
356 } 359 }
357 360
358 void NativeThemeGtk3::PaintMenuPopupBackground( 361 void NativeThemeGtk3::PaintMenuPopupBackground(
359 SkCanvas* canvas, 362 SkCanvas* canvas,
360 const gfx::Size& size, 363 const gfx::Size& size,
361 const MenuBackgroundExtraParams& menu_background) const { 364 const MenuBackgroundExtraParams& menu_background) const {
362 PaintWidget(canvas, gfx::Rect(size), "GtkMenu#menu", GTK_STATE_FLAG_NORMAL); 365 PaintWidget(canvas, gfx::Rect(size), GetStyleContextFromCss("GtkMenu#menu"));
363 } 366 }
364 367
365 void NativeThemeGtk3::PaintMenuItemBackground( 368 void NativeThemeGtk3::PaintMenuItemBackground(
366 SkCanvas* canvas, 369 SkCanvas* canvas,
367 State state, 370 State state,
368 const gfx::Rect& rect, 371 const gfx::Rect& rect,
369 const MenuItemExtraParams& menu_item) const { 372 const MenuItemExtraParams& menu_item) const {
370 PaintWidget(canvas, rect, "GtkMenu#menu GtkMenuItem#menuitem", 373 auto context = GetStyleContextFromCss("GtkMenu#menu GtkMenuItem#menuitem");
371 StateToStateFlags(state)); 374 gtk_style_context_set_state(context, StateToStateFlags(state));
375 PaintWidget(canvas, rect, context);
376 }
377
378 void NativeThemeGtk3::PaintFrameTopArea(
379 SkCanvas* canvas,
380 State state,
381 const gfx::Rect& rect,
382 const FrameTopAreaExtraParams& frame_top_area) const {
383 auto context = GetStyleContextFromCss(frame_top_area.use_custom_frame
384 ? "#headerbar.header-bar.titlebar"
385 : "GtkMenuBar#menubar");
386 RemoveBorders(context);
387 gtk_style_context_set_state(context,
388 frame_top_area.is_active
389 ? GTK_STATE_FLAG_NORMAL
390 : GTK_STATE_FLAG_BACKDROP);
391
392 SkBitmap bitmap = GetWidgetBitmap(rect.size(), context);
393
394 if (frame_top_area.incognito) {
395 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap(
396 bitmap, kDefaultTintFrameIncognito);
397 }
398
399 canvas->drawBitmap(bitmap, rect.x(), rect.y());
372 } 400 }
373 401
374 } // namespace libgtkui 402 } // namespace libgtkui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk3.h ('k') | chrome/browser/ui/views/frame/opaque_browser_frame_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698