| OLD | NEW |
| 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 gtk_render_background(context, cr, 0, 0, size.width(), size.height()); |
| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 333 |
| 332 SkColor color = SkColorFromColorId(color_id); | 334 SkColor color = SkColorFromColorId(color_id); |
| 333 color_cache_[color_id] = color; | 335 color_cache_[color_id] = color; |
| 334 return color; | 336 return color; |
| 335 } | 337 } |
| 336 | 338 |
| 337 void NativeThemeGtk3::PaintMenuPopupBackground( | 339 void NativeThemeGtk3::PaintMenuPopupBackground( |
| 338 SkCanvas* canvas, | 340 SkCanvas* canvas, |
| 339 const gfx::Size& size, | 341 const gfx::Size& size, |
| 340 const MenuBackgroundExtraParams& menu_background) const { | 342 const MenuBackgroundExtraParams& menu_background) const { |
| 341 PaintWidget(canvas, gfx::Rect(size), "GtkMenu#menu", GTK_STATE_FLAG_NORMAL); | 343 PaintWidget(canvas, gfx::Rect(size), GetStyleContextFromCss("GtkMenu#menu")); |
| 342 } | 344 } |
| 343 | 345 |
| 344 void NativeThemeGtk3::PaintMenuItemBackground( | 346 void NativeThemeGtk3::PaintMenuItemBackground( |
| 345 SkCanvas* canvas, | 347 SkCanvas* canvas, |
| 346 State state, | 348 State state, |
| 347 const gfx::Rect& rect, | 349 const gfx::Rect& rect, |
| 348 const MenuItemExtraParams& menu_item) const { | 350 const MenuItemExtraParams& menu_item) const { |
| 349 PaintWidget(canvas, rect, "GtkMenu#menu GtkMenuItem#menuitem", | 351 auto context = GetStyleContextFromCss("GtkMenu#menu GtkMenuItem#menuitem"); |
| 350 StateToStateFlags(state)); | 352 gtk_style_context_set_state(context, StateToStateFlags(state)); |
| 353 PaintWidget(canvas, rect, context); |
| 354 } |
| 355 |
| 356 void NativeThemeGtk3::PaintFrameTopArea( |
| 357 SkCanvas* canvas, |
| 358 State state, |
| 359 const gfx::Rect& rect, |
| 360 const FrameTopAreaExtraParams& frame_top_area) const { |
| 361 auto context = GetStyleContextFromCss("#headerbar.header-bar.titlebar"); |
| 362 RemoveBorders(context); |
| 363 gtk_style_context_set_state(context, |
| 364 frame_top_area.is_active |
| 365 ? GTK_STATE_FLAG_NORMAL |
| 366 : GTK_STATE_FLAG_BACKDROP); |
| 367 |
| 368 SkBitmap bitmap = GetWidgetBitmap(rect.size(), context); |
| 369 |
| 370 if (frame_top_area.incognito) { |
| 371 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
| 372 bitmap, kDefaultTintFrameIncognito); |
| 373 } |
| 374 |
| 375 canvas->drawBitmap(bitmap, rect.x(), rect.y()); |
| 351 } | 376 } |
| 352 | 377 |
| 353 } // namespace libgtkui | 378 } // namespace libgtkui |
| OLD | NEW |