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

Unified 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: Handle incognito 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/libgtkui/native_theme_gtk3.cc
diff --git a/chrome/browser/ui/libgtkui/native_theme_gtk3.cc b/chrome/browser/ui/libgtkui/native_theme_gtk3.cc
index 84de8bda62613352f85ba48c93b42de0a3952cfd..50b9624ef14df072b583fef8e526315124d2a940 100644
--- a/chrome/browser/ui/libgtkui/native_theme_gtk3.cc
+++ b/chrome/browser/ui/libgtkui/native_theme_gtk3.cc
@@ -13,34 +13,36 @@
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/skbitmap_operations.h"
#include "ui/native_theme/native_theme_dark_aura.h"
namespace libgtkui {
namespace {
-void PaintWidget(SkCanvas* canvas,
- const gfx::Rect& rect,
- const char* css_selector,
- GtkStateFlags state) {
+SkBitmap GetWidgetBitmap(const gfx::Size& size,
+ GtkStyleContext* context) {
SkBitmap bitmap;
- bitmap.allocN32Pixels(rect.width(), rect.height());
+ bitmap.allocN32Pixels(size.width(), size.height());
bitmap.eraseColor(0);
cairo_surface_t* surface = cairo_image_surface_create_for_data(
static_cast<unsigned char*>(bitmap.getAddr(0, 0)), CAIRO_FORMAT_ARGB32,
- rect.width(), rect.height(),
- cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, rect.width()));
+ size.width(), size.height(),
+ cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, size.width()));
cairo_t* cr = cairo_create(surface);
- auto context = GetStyleContextFromCss(css_selector);
- gtk_style_context_set_state(context, state);
-
- gtk_render_background(context, cr, 0, 0, rect.width(), rect.height());
- gtk_render_frame(context, cr, 0, 0, rect.width(), rect.height());
+ gtk_render_background(context, cr, 0, 0, size.width(), size.height());
+ gtk_render_frame(context, cr, 0, 0, size.width(), size.height());
cairo_destroy(cr);
cairo_surface_destroy(surface);
- canvas->drawBitmap(bitmap, rect.x(), rect.y());
+ return bitmap;
+}
+
+void PaintWidget(SkCanvas* canvas,
+ const gfx::Rect& rect,
+ GtkStyleContext* context) {
+ canvas->drawBitmap(GetWidgetBitmap(rect.size(), context), rect.x(), rect.y());
}
GtkStateFlags StateToStateFlags(NativeThemeGtk3::State state) {
@@ -338,7 +340,7 @@ void NativeThemeGtk3::PaintMenuPopupBackground(
SkCanvas* canvas,
const gfx::Size& size,
const MenuBackgroundExtraParams& menu_background) const {
- PaintWidget(canvas, gfx::Rect(size), "GtkMenu#menu", GTK_STATE_FLAG_NORMAL);
+ PaintWidget(canvas, gfx::Rect(size), GetStyleContextFromCss("GtkMenu#menu"));
}
void NativeThemeGtk3::PaintMenuItemBackground(
@@ -346,8 +348,31 @@ void NativeThemeGtk3::PaintMenuItemBackground(
State state,
const gfx::Rect& rect,
const MenuItemExtraParams& menu_item) const {
- PaintWidget(canvas, rect, "GtkMenu#menu GtkMenuItem#menuitem",
- StateToStateFlags(state));
+ auto context = GetStyleContextFromCss("GtkMenu#menu GtkMenuItem#menuitem");
+ gtk_style_context_set_state(context, StateToStateFlags(state));
+ PaintWidget(canvas, rect, context);
+}
+
+void NativeThemeGtk3::PaintFrameTopArea(
+ SkCanvas* canvas,
+ State state,
+ const gfx::Rect& rect,
+ const FrameTopAreaExtraParams& frame_top_area) const {
+ auto context = GetStyleContextFromCss("#headerbar.header-bar.titlebar");
+ RemoveBorders(context);
+ gtk_style_context_set_state(context,
+ frame_top_area.is_active
+ ? GTK_STATE_FLAG_NORMAL
+ : GTK_STATE_FLAG_BACKDROP);
+
+ SkBitmap bitmap = GetWidgetBitmap(rect.size(), context);
+
+ if (frame_top_area.incognito) {
+ bitmap = SkBitmapOperations::CreateHSLShiftedBitmap(
+ bitmap, kDefaultTintFrameIncognito);
+ }
+
+ canvas->drawBitmap(bitmap, rect.x(), rect.y());
}
} // namespace libgtkui

Powered by Google App Engine
This is Rietveld 408576698