| 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" |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 417 |
| 418 SkColor NativeThemeGtk3::GetSystemColor(ColorId color_id) const { | 418 SkColor NativeThemeGtk3::GetSystemColor(ColorId color_id) const { |
| 419 if (color_cache_[color_id]) | 419 if (color_cache_[color_id]) |
| 420 return color_cache_[color_id].value(); | 420 return color_cache_[color_id].value(); |
| 421 | 421 |
| 422 SkColor color = SkColorFromColorId(color_id); | 422 SkColor color = SkColorFromColorId(color_id); |
| 423 color_cache_[color_id] = color; | 423 color_cache_[color_id] = color; |
| 424 return color; | 424 return color; |
| 425 } | 425 } |
| 426 | 426 |
| 427 void NativeThemeGtk3::PaintArrowButton(SkCanvas* canvas, | 427 void NativeThemeGtk3::PaintArrowButton(cc::PaintCanvas* canvas, |
| 428 const gfx::Rect& rect, | 428 const gfx::Rect& rect, |
| 429 Part direction, | 429 Part direction, |
| 430 State state) const { | 430 State state) const { |
| 431 auto context = GetStyleContextFromCss( | 431 auto context = GetStyleContextFromCss( |
| 432 GtkVersionCheck(3, 20) | 432 GtkVersionCheck(3, 20) |
| 433 ? "GtkScrollbar#scrollbar #contents GtkButton#button" | 433 ? "GtkScrollbar#scrollbar #contents GtkButton#button" |
| 434 : "GtkRange.scrollbar.button"); | 434 : "GtkRange.scrollbar.button"); |
| 435 GtkStateFlags state_flags = StateToStateFlags(state); | 435 GtkStateFlags state_flags = StateToStateFlags(state); |
| 436 gtk_style_context_set_state(context, state_flags); | 436 gtk_style_context_set_state(context, state_flags); |
| 437 | 437 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 450 break; | 450 break; |
| 451 default: | 451 default: |
| 452 NOTREACHED(); | 452 NOTREACHED(); |
| 453 } | 453 } |
| 454 | 454 |
| 455 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); | 455 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); |
| 456 PaintArrow(canvas, rect, direction, GetFgColorFromStyleContext(context)); | 456 PaintArrow(canvas, rect, direction, GetFgColorFromStyleContext(context)); |
| 457 } | 457 } |
| 458 | 458 |
| 459 void NativeThemeGtk3::PaintScrollbarTrack( | 459 void NativeThemeGtk3::PaintScrollbarTrack( |
| 460 SkCanvas* canvas, | 460 cc::PaintCanvas* canvas, |
| 461 Part part, | 461 Part part, |
| 462 State state, | 462 State state, |
| 463 const ScrollbarTrackExtraParams& extra_params, | 463 const ScrollbarTrackExtraParams& extra_params, |
| 464 const gfx::Rect& rect) const { | 464 const gfx::Rect& rect) const { |
| 465 PaintWidget(canvas, rect, GetStyleContextFromCss( | 465 PaintWidget(canvas, rect, GetStyleContextFromCss( |
| 466 GtkVersionCheck(3, 20) | 466 GtkVersionCheck(3, 20) |
| 467 ? "GtkScrollbar#scrollbar #contents #trough" | 467 ? "GtkScrollbar#scrollbar #contents #trough" |
| 468 : "GtkScrollbar.scrollbar.trough"), | 468 : "GtkScrollbar.scrollbar.trough"), |
| 469 BG_RENDER_NORMAL, true); | 469 BG_RENDER_NORMAL, true); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void NativeThemeGtk3::PaintScrollbarThumb( | 472 void NativeThemeGtk3::PaintScrollbarThumb( |
| 473 SkCanvas* canvas, | 473 cc::PaintCanvas* canvas, |
| 474 Part part, | 474 Part part, |
| 475 State state, | 475 State state, |
| 476 const gfx::Rect& rect, | 476 const gfx::Rect& rect, |
| 477 NativeTheme::ScrollbarOverlayColorTheme theme) const { | 477 NativeTheme::ScrollbarOverlayColorTheme theme) const { |
| 478 auto context = GetStyleContextFromCss( | 478 auto context = GetStyleContextFromCss( |
| 479 GtkVersionCheck(3, 20) | 479 GtkVersionCheck(3, 20) |
| 480 ? "GtkScrollbar#scrollbar #contents #trough #slider" | 480 ? "GtkScrollbar#scrollbar #contents #trough #slider" |
| 481 : "GtkScrollbar.scrollbar.slider"); | 481 : "GtkScrollbar.scrollbar.slider"); |
| 482 gtk_style_context_set_state(context, StateToStateFlags(state)); | 482 gtk_style_context_set_state(context, StateToStateFlags(state)); |
| 483 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); | 483 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void NativeThemeGtk3::PaintScrollbarCorner(SkCanvas* canvas, | 486 void NativeThemeGtk3::PaintScrollbarCorner(cc::PaintCanvas* canvas, |
| 487 State state, | 487 State state, |
| 488 const gfx::Rect& rect) const { | 488 const gfx::Rect& rect) const { |
| 489 auto context = GetStyleContextFromCss( | 489 auto context = GetStyleContextFromCss( |
| 490 GtkVersionCheck(3, 19, 2) | 490 GtkVersionCheck(3, 19, 2) |
| 491 ? "GtkScrolledWindow#scrolledwindow #junction" | 491 ? "GtkScrolledWindow#scrolledwindow #junction" |
| 492 : "GtkScrolledWindow.scrolledwindow.scrollbars-junction"); | 492 : "GtkScrolledWindow.scrolledwindow.scrollbars-junction"); |
| 493 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); | 493 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void NativeThemeGtk3::PaintMenuPopupBackground( | 496 void NativeThemeGtk3::PaintMenuPopupBackground( |
| 497 cc::PaintCanvas* canvas, | 497 cc::PaintCanvas* canvas, |
| 498 const gfx::Size& size, | 498 const gfx::Size& size, |
| 499 const MenuBackgroundExtraParams& menu_background) const { | 499 const MenuBackgroundExtraParams& menu_background) const { |
| 500 PaintWidget(canvas, gfx::Rect(size), GetStyleContextFromCss("GtkMenu#menu"), | 500 PaintWidget(canvas, gfx::Rect(size), GetStyleContextFromCss("GtkMenu#menu"), |
| 501 BG_RENDER_RECURSIVE, false); | 501 BG_RENDER_RECURSIVE, false); |
| 502 } | 502 } |
| 503 | 503 |
| 504 void NativeThemeGtk3::PaintMenuItemBackground( | 504 void NativeThemeGtk3::PaintMenuItemBackground( |
| 505 cc::PaintCanvas* canvas, | 505 cc::PaintCanvas* canvas, |
| 506 State state, | 506 State state, |
| 507 const gfx::Rect& rect, | 507 const gfx::Rect& rect, |
| 508 const MenuItemExtraParams& menu_item) const { | 508 const MenuItemExtraParams& menu_item) const { |
| 509 auto context = GetStyleContextFromCss("GtkMenu#menu GtkMenuItem#menuitem"); | 509 auto context = GetStyleContextFromCss("GtkMenu#menu GtkMenuItem#menuitem"); |
| 510 gtk_style_context_set_state(context, StateToStateFlags(state)); | 510 gtk_style_context_set_state(context, StateToStateFlags(state)); |
| 511 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); | 511 PaintWidget(canvas, rect, context, BG_RENDER_NORMAL, true); |
| 512 } | 512 } |
| 513 | 513 |
| 514 void NativeThemeGtk3::PaintMenuSeparator( | 514 void NativeThemeGtk3::PaintMenuSeparator( |
| 515 SkCanvas* canvas, | 515 cc::PaintCanvas* canvas, |
| 516 State state, | 516 State state, |
| 517 const gfx::Rect& rect, | 517 const gfx::Rect& rect, |
| 518 const MenuSeparatorExtraParams& menu_separator) const { | 518 const MenuSeparatorExtraParams& menu_separator) const { |
| 519 auto separator_offset = [&](int separator_thickness) { | 519 auto separator_offset = [&](int separator_thickness) { |
| 520 switch (menu_separator.type) { | 520 switch (menu_separator.type) { |
| 521 case ui::LOWER_SEPARATOR: | 521 case ui::LOWER_SEPARATOR: |
| 522 return rect.height() - separator_thickness; | 522 return rect.height() - separator_thickness; |
| 523 case ui::UPPER_SEPARATOR: | 523 case ui::UPPER_SEPARATOR: |
| 524 return 0; | 524 return 0; |
| 525 default: | 525 default: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 555 GtkBorder padding; | 555 GtkBorder padding; |
| 556 gtk_style_context_get_padding(context, gtk_style_context_get_state(context), | 556 gtk_style_context_get_padding(context, gtk_style_context_get_state(context), |
| 557 &padding); | 557 &padding); |
| 558 int w = rect.width() - padding.left - padding.right; | 558 int w = rect.width() - padding.left - padding.right; |
| 559 int x = rect.x() + padding.left; | 559 int x = rect.x() + padding.left; |
| 560 int h = wide_separators ? separator_height : 1; | 560 int h = wide_separators ? separator_height : 1; |
| 561 int y = rect.y() + separator_offset(h); | 561 int y = rect.y() + separator_offset(h); |
| 562 if (wide_separators) { | 562 if (wide_separators) { |
| 563 PaintWidget(canvas, gfx::Rect(x, y, w, h), context, BG_RENDER_NONE, true); | 563 PaintWidget(canvas, gfx::Rect(x, y, w, h), context, BG_RENDER_NONE, true); |
| 564 } else { | 564 } else { |
| 565 SkPaint paint; | 565 cc::PaintFlags flags; |
| 566 paint.setColor(GetFgColorFromStyleContext(context)); | 566 flags.setColor(GetFgColorFromStyleContext(context)); |
| 567 canvas->drawLine(x, y, x + w, y, paint); | 567 canvas->drawLine(x, y, x + w, y, flags); |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 | 571 |
| 572 void NativeThemeGtk3::PaintFrameTopArea( | 572 void NativeThemeGtk3::PaintFrameTopArea( |
| 573 cc::PaintCanvas* canvas, | 573 cc::PaintCanvas* canvas, |
| 574 State state, | 574 State state, |
| 575 const gfx::Rect& rect, | 575 const gfx::Rect& rect, |
| 576 const FrameTopAreaExtraParams& frame_top_area) const { | 576 const FrameTopAreaExtraParams& frame_top_area) const { |
| 577 auto context = GetStyleContextFromCss(frame_top_area.use_custom_frame | 577 auto context = GetStyleContextFromCss(frame_top_area.use_custom_frame |
| 578 ? "#headerbar.header-bar.titlebar" | 578 ? "#headerbar.header-bar.titlebar" |
| 579 : "GtkMenuBar#menubar"); | 579 : "GtkMenuBar#menubar"); |
| 580 ApplyCssToContext(context, "* { border-radius: 0px; border-style: none; }"); | 580 ApplyCssToContext(context, "* { border-radius: 0px; border-style: none; }"); |
| 581 gtk_style_context_set_state(context, frame_top_area.is_active | 581 gtk_style_context_set_state(context, frame_top_area.is_active |
| 582 ? GTK_STATE_FLAG_NORMAL | 582 ? GTK_STATE_FLAG_NORMAL |
| 583 : GTK_STATE_FLAG_BACKDROP); | 583 : GTK_STATE_FLAG_BACKDROP); |
| 584 | 584 |
| 585 SkBitmap bitmap = | 585 SkBitmap bitmap = |
| 586 GetWidgetBitmap(rect.size(), context, BG_RENDER_RECURSIVE, false); | 586 GetWidgetBitmap(rect.size(), context, BG_RENDER_RECURSIVE, false); |
| 587 | 587 |
| 588 if (frame_top_area.incognito) { | 588 if (frame_top_area.incognito) { |
| 589 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( | 589 bitmap = SkBitmapOperations::CreateHSLShiftedBitmap( |
| 590 bitmap, kDefaultTintFrameIncognito); | 590 bitmap, kDefaultTintFrameIncognito); |
| 591 } | 591 } |
| 592 | 592 |
| 593 canvas->drawBitmap(bitmap, rect.x(), rect.y()); | 593 canvas->drawBitmap(bitmap, rect.x(), rect.y()); |
| 594 } | 594 } |
| 595 | 595 |
| 596 } // namespace libgtkui | 596 } // namespace libgtkui |
| OLD | NEW |