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