| 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/native_theme/native_theme_dark_aura.h" | 16 #include "ui/native_theme/native_theme_dark_aura.h" |
| 17 | 17 |
| 18 namespace libgtkui { | 18 namespace libgtkui { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 void PaintWidget(SkCanvas* canvas, | 22 void PaintWidget(SkCanvas* canvas, |
| 23 const gfx::Rect& rect, | 23 const gfx::Rect& rect, |
| 24 const char* css_selector, | 24 GtkStyleContext* context) { |
| 25 GtkStateFlags state) { | |
| 26 SkBitmap bitmap; | 25 SkBitmap bitmap; |
| 27 bitmap.allocN32Pixels(rect.width(), rect.height()); | 26 bitmap.allocN32Pixels(rect.width(), rect.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 rect.width(), rect.height(), |
| 33 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, rect.width())); | 32 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, rect.width())); |
| 34 cairo_t* cr = cairo_create(surface); | 33 cairo_t* cr = cairo_create(surface); |
| 35 | 34 |
| 36 auto context = GetStyleContextFromCss(css_selector); | |
| 37 gtk_style_context_set_state(context, state); | |
| 38 | |
| 39 gtk_render_background(context, cr, 0, 0, rect.width(), rect.height()); | 35 gtk_render_background(context, cr, 0, 0, rect.width(), rect.height()); |
| 40 gtk_render_frame(context, cr, 0, 0, rect.width(), rect.height()); | 36 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 canvas->drawBitmap(bitmap, rect.x(), rect.y()); |
| 44 } | 40 } |
| 45 | 41 |
| 46 GtkStateFlags StateToStateFlags(NativeThemeGtk3::State state) { | 42 GtkStateFlags StateToStateFlags(NativeThemeGtk3::State state) { |
| 47 switch (state) { | 43 switch (state) { |
| 48 case NativeThemeGtk3::kDisabled: | 44 case NativeThemeGtk3::kDisabled: |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 327 |
| 332 SkColor color = SkColorFromColorId(color_id); | 328 SkColor color = SkColorFromColorId(color_id); |
| 333 color_cache_[color_id] = color; | 329 color_cache_[color_id] = color; |
| 334 return color; | 330 return color; |
| 335 } | 331 } |
| 336 | 332 |
| 337 void NativeThemeGtk3::PaintMenuPopupBackground( | 333 void NativeThemeGtk3::PaintMenuPopupBackground( |
| 338 SkCanvas* canvas, | 334 SkCanvas* canvas, |
| 339 const gfx::Size& size, | 335 const gfx::Size& size, |
| 340 const MenuBackgroundExtraParams& menu_background) const { | 336 const MenuBackgroundExtraParams& menu_background) const { |
| 341 PaintWidget(canvas, gfx::Rect(size), "GtkMenu#menu", GTK_STATE_FLAG_NORMAL); | 337 PaintWidget(canvas, gfx::Rect(size), GetStyleContextFromCss("GtkMenu#menu")); |
| 342 } | 338 } |
| 343 | 339 |
| 344 void NativeThemeGtk3::PaintMenuItemBackground( | 340 void NativeThemeGtk3::PaintMenuItemBackground( |
| 345 SkCanvas* canvas, | 341 SkCanvas* canvas, |
| 346 State state, | 342 State state, |
| 347 const gfx::Rect& rect, | 343 const gfx::Rect& rect, |
| 348 const MenuItemExtraParams& menu_item) const { | 344 const MenuItemExtraParams& menu_item) const { |
| 349 PaintWidget(canvas, rect, "GtkMenu#menu GtkMenuItem#menuitem", | 345 auto context = GetStyleContextFromCss("GtkMenu#menu GtkMenuItem#menuitem"); |
| 350 StateToStateFlags(state)); | 346 gtk_style_context_set_state(context, StateToStateFlags(state)); |
| 347 PaintWidget(canvas, rect, context); |
| 348 } |
| 349 |
| 350 void NativeThemeGtk3::PaintFrameTopArea( |
| 351 SkCanvas* canvas, |
| 352 State state, |
| 353 const gfx::Rect& rect, |
| 354 const FrameTopAreaExtraParams& frame_top_area) const { |
| 355 auto context = GetStyleContextFromCss("#headerbar.header-bar.titlebar"); |
| 356 RemoveBorders(context); |
| 357 gtk_style_context_set_state(context, |
| 358 frame_top_area.is_active |
| 359 ? GTK_STATE_FLAG_NORMAL |
| 360 : GTK_STATE_FLAG_BACKDROP); |
| 361 PaintWidget(canvas, rect, context); |
| 351 } | 362 } |
| 352 | 363 |
| 353 } // namespace libgtkui | 364 } // namespace libgtkui |
| OLD | NEW |