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

Side by Side Diff: chrome/browser/themes/theme_service.cc

Issue 1744483002: Monitor the system native frame color on Win 10. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "ui/native_theme/native_theme.h" 47 #include "ui/native_theme/native_theme.h"
48 48
49 #if defined(ENABLE_EXTENSIONS) 49 #if defined(ENABLE_EXTENSIONS)
50 #include "extensions/browser/extension_registry_observer.h" 50 #include "extensions/browser/extension_registry_observer.h"
51 #endif 51 #endif
52 52
53 #if defined(ENABLE_SUPERVISED_USERS) 53 #if defined(ENABLE_SUPERVISED_USERS)
54 #include "chrome/browser/supervised_user/supervised_user_theme.h" 54 #include "chrome/browser/supervised_user/supervised_user_theme.h"
55 #endif 55 #endif
56 56
57 #if defined(OS_WIN)
58 #include "ui/base/win/shell.h"
59 #endif
60
61 using base::UserMetricsAction; 57 using base::UserMetricsAction;
62 using content::BrowserThread; 58 using content::BrowserThread;
63 using extensions::Extension; 59 using extensions::Extension;
64 using extensions::UnloadedExtensionInfo; 60 using extensions::UnloadedExtensionInfo;
65 using ui::ResourceBundle; 61 using ui::ResourceBundle;
66 62
67 63
68 // Helpers -------------------------------------------------------------------- 64 // Helpers --------------------------------------------------------------------
69 65
70 namespace { 66 namespace {
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 scoped_refptr<CustomThemeSupplier> theme_supplier) { 402 scoped_refptr<CustomThemeSupplier> theme_supplier) {
407 ClearAllThemeData(); 403 ClearAllThemeData();
408 SwapThemeSupplier(theme_supplier); 404 SwapThemeSupplier(theme_supplier);
409 NotifyThemeChanged(); 405 NotifyThemeChanged();
410 } 406 }
411 407
412 bool ThemeService::ShouldInitWithSystemTheme() const { 408 bool ThemeService::ShouldInitWithSystemTheme() const {
413 return false; 409 return false;
414 } 410 }
415 411
412 SkColor ThemeService::GetDefaultColor(int id, bool incognito) const {
413 // For backward compat with older themes, some newer colors are generated from
414 // older ones if they are missing.
415 const int kNtpText = ThemeProperties::COLOR_NTP_TEXT;
416 const int kLabelBackground =
417 ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND;
418 switch (id) {
419 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON:
420 return color_utils::HSLShift(
421 gfx::kChromeIconGrey,
422 GetTint(ThemeProperties::TINT_BUTTONS, incognito));
423 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE:
424 // The active color is overridden in Gtk2UI.
425 return SkColorSetA(
426 GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito),
427 0x33);
428 case ThemeProperties::COLOR_BACKGROUND_TAB: {
429 // The tints here serve a different purpose than TINT_BACKGROUND_TAB.
430 // That tint is used to create background tab images for custom themes by
431 // lightening the frame images. The tints here create solid colors for
432 // background tabs by darkening the foreground tab (toolbar) color.
433 const color_utils::HSL kTint = {-1, -1, 0.4296875};
434 const color_utils::HSL kTintIncognito = {-1, -1, 0.34375};
435 return color_utils::HSLShift(
436 GetColor(ThemeProperties::COLOR_TOOLBAR, incognito),
437 incognito ? kTintIncognito : kTint);
438 }
439 case ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND:
440 if (UsingDefaultTheme())
441 break;
442 return GetColor(ThemeProperties::COLOR_TOOLBAR, incognito);
443 case ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR:
444 if (UsingDefaultTheme())
445 break;
446 // Use 50% of bookmark text color as separator color.
447 return SkColorSetA(
448 GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT, incognito), 128);
449 case ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT:
450 return IncreaseLightness(GetColor(kNtpText, incognito), 0.30);
451 case ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER:
452 return GetColor(kNtpText, incognito);
453 case ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE:
454 return IncreaseLightness(GetColor(kNtpText, incognito), 0.70);
455 case ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT:
456 return IncreaseLightness(GetColor(kNtpText, incognito), 0.86);
457 case ThemeProperties::COLOR_NTP_TEXT_LIGHT:
458 return IncreaseLightness(GetColor(kNtpText, incognito), 0.40);
459 case ThemeProperties::COLOR_TAB_THROBBER_SPINNING:
460 case ThemeProperties::COLOR_TAB_THROBBER_WAITING: {
461 SkColor base_color =
462 ui::GetAuraColor(id == ThemeProperties::COLOR_TAB_THROBBER_SPINNING
463 ? ui::NativeTheme::kColorId_ThrobberSpinningColor
464 : ui::NativeTheme::kColorId_ThrobberWaitingColor,
465 nullptr);
466 color_utils::HSL hsl = GetTint(ThemeProperties::TINT_BUTTONS, incognito);
467 return color_utils::HSLShift(base_color, hsl);
468 }
469 #if defined(ENABLE_SUPERVISED_USERS)
470 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL:
471 return color_utils::GetReadableColor(
472 SK_ColorWHITE, GetColor(kLabelBackground, incognito));
473 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND:
474 return color_utils::BlendTowardOppositeLuminance(
475 GetColor(ThemeProperties::COLOR_FRAME, incognito), 0x80);
476 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BORDER:
477 return color_utils::AlphaBlend(GetColor(kLabelBackground, incognito),
478 SK_ColorBLACK, 230);
479 #endif
480 case ThemeProperties::COLOR_STATUS_BAR_TEXT: {
481 // A long time ago, we blended the toolbar and the tab text together to
482 // get the status bar text because, at the time, our text rendering in
483 // views couldn't do alpha blending. Even though this is no longer the
484 // case, this blending decision is built into the majority of themes that
485 // exist, and we must keep doing it.
486 SkColor toolbar_color =
487 GetColor(ThemeProperties::COLOR_TOOLBAR, incognito);
488 SkColor text_color = GetColor(ThemeProperties::COLOR_TAB_TEXT, incognito);
489 return SkColorSetARGB(
490 SkColorGetA(text_color),
491 (SkColorGetR(text_color) + SkColorGetR(toolbar_color)) / 2,
492 (SkColorGetG(text_color) + SkColorGetR(toolbar_color)) / 2,
493 (SkColorGetB(text_color) + SkColorGetR(toolbar_color)) / 2);
494 }
495 }
496
497 return ThemeProperties::GetDefaultColor(id, incognito);
498 }
499
416 color_utils::HSL ThemeService::GetTint(int id, bool incognito) const { 500 color_utils::HSL ThemeService::GetTint(int id, bool incognito) const {
417 DCHECK(CalledOnValidThread()); 501 DCHECK(CalledOnValidThread());
418 502
419 color_utils::HSL hsl; 503 color_utils::HSL hsl;
420 if (theme_supplier_ && theme_supplier_->GetTint(id, &hsl)) 504 if (theme_supplier_ && theme_supplier_->GetTint(id, &hsl))
421 return hsl; 505 return hsl;
422 506
423 return ThemeProperties::GetDefaultTint(id, incognito); 507 return ThemeProperties::GetDefaultTint(id, incognito);
424 } 508 }
425 509
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 theme_syncable_service_->OnThemeChange(); 590 theme_syncable_service_->OnThemeChange();
507 } 591 }
508 } 592 }
509 593
510 #if defined(USE_AURA) 594 #if defined(USE_AURA)
511 void ThemeService::FreePlatformCaches() { 595 void ThemeService::FreePlatformCaches() {
512 // Views (Skia) has no platform image cache to clear. 596 // Views (Skia) has no platform image cache to clear.
513 } 597 }
514 #endif 598 #endif
515 599
600 bool ThemeService::ShouldUseNativeFrame() const {
601 return false;
602 }
603
604 bool ThemeService::HasCustomImage(int id) const {
605 return BrowserThemePack::IsPersistentImageID(id) && theme_supplier_ &&
606 theme_supplier_->HasCustomImage(id);
607 }
608
516 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const { 609 gfx::ImageSkia* ThemeService::GetImageSkiaNamed(int id, bool incognito) const {
517 gfx::Image image = GetImageNamed(id, incognito); 610 gfx::Image image = GetImageNamed(id, incognito);
518 if (image.IsEmpty()) 611 if (image.IsEmpty())
519 return nullptr; 612 return nullptr;
520 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns 613 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns
521 // its images const. GetImageSkiaNamed() also should but has many callsites. 614 // its images const. GetImageSkiaNamed() also should but has many callsites.
522 return const_cast<gfx::ImageSkia*>(image.ToImageSkia()); 615 return const_cast<gfx::ImageSkia*>(image.ToImageSkia());
523 } 616 }
524 617
525 SkColor ThemeService::GetColor(int id, bool incognito) const { 618 SkColor ThemeService::GetColor(int id, bool incognito) const {
526 DCHECK(CalledOnValidThread()); 619 DCHECK(CalledOnValidThread());
527 620
528 // For legacy reasons, |theme_supplier_| requires the incognito variants 621 // For legacy reasons, |theme_supplier_| requires the incognito variants
529 // of color IDs. 622 // of color IDs.
530 int theme_supplier_id = id; 623 int theme_supplier_id = id;
531 if (incognito) { 624 if (incognito) {
532 if (id == ThemeProperties::COLOR_FRAME) 625 if (id == ThemeProperties::COLOR_FRAME)
533 theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO; 626 theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO;
534 else if (id == ThemeProperties::COLOR_FRAME_INACTIVE) 627 else if (id == ThemeProperties::COLOR_FRAME_INACTIVE)
535 theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE; 628 theme_supplier_id = ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE;
536 } 629 }
537 630
538 SkColor color; 631 SkColor color;
539 if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color)) 632 if (theme_supplier_ && theme_supplier_->GetColor(theme_supplier_id, &color))
540 return color; 633 return color;
541 634
542 // For backward compat with older themes, some newer colors are generated from 635 return GetDefaultColor(id, incognito);
543 // older ones if they are missing.
544 const int kNtpText = ThemeProperties::COLOR_NTP_TEXT;
545 const int kLabelBackground =
546 ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND;
547 switch (id) {
548 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON:
549 return color_utils::HSLShift(
550 gfx::kChromeIconGrey,
551 GetTint(ThemeProperties::TINT_BUTTONS, incognito));
552 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE:
553 // The active color is overridden in Gtk2UI.
554 return SkColorSetA(
555 GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito),
556 0x33);
557 case ThemeProperties::COLOR_BACKGROUND_TAB: {
558 // The tints here serve a different purpose than TINT_BACKGROUND_TAB.
559 // That tint is used to create background tab images for custom themes by
560 // lightening the frame images. The tints here create solid colors for
561 // background tabs by darkening the foreground tab (toolbar) color.
562 const color_utils::HSL kTint = {-1, -1, 0.4296875};
563 const color_utils::HSL kTintIncognito = {-1, -1, 0.34375};
564 return color_utils::HSLShift(
565 GetColor(ThemeProperties::COLOR_TOOLBAR, incognito),
566 incognito ? kTintIncognito : kTint);
567 }
568 case ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND:
569 if (UsingDefaultTheme())
570 break;
571 return GetColor(ThemeProperties::COLOR_TOOLBAR, incognito);
572 case ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR:
573 if (UsingDefaultTheme())
574 break;
575 // Use 50% of bookmark text color as separator color.
576 return SkColorSetA(
577 GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT, incognito), 128);
578 case ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT:
579 return IncreaseLightness(GetColor(kNtpText, incognito), 0.30);
580 case ThemeProperties::COLOR_NTP_SECTION_HEADER_TEXT_HOVER:
581 return GetColor(kNtpText, incognito);
582 case ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE:
583 return IncreaseLightness(GetColor(kNtpText, incognito), 0.70);
584 case ThemeProperties::COLOR_NTP_SECTION_HEADER_RULE_LIGHT:
585 return IncreaseLightness(GetColor(kNtpText, incognito), 0.86);
586 case ThemeProperties::COLOR_NTP_TEXT_LIGHT:
587 return IncreaseLightness(GetColor(kNtpText, incognito), 0.40);
588 case ThemeProperties::COLOR_TAB_THROBBER_SPINNING:
589 case ThemeProperties::COLOR_TAB_THROBBER_WAITING: {
590 SkColor base_color =
591 ui::GetAuraColor(id == ThemeProperties::COLOR_TAB_THROBBER_SPINNING
592 ? ui::NativeTheme::kColorId_ThrobberSpinningColor
593 : ui::NativeTheme::kColorId_ThrobberWaitingColor,
594 nullptr);
595 color_utils::HSL hsl = GetTint(ThemeProperties::TINT_BUTTONS, incognito);
596 return color_utils::HSLShift(base_color, hsl);
597 }
598 #if defined(ENABLE_SUPERVISED_USERS)
599 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL:
600 return color_utils::GetReadableColor(
601 SK_ColorWHITE, GetColor(kLabelBackground, incognito));
602 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND:
603 return color_utils::BlendTowardOppositeLuminance(
604 GetColor(ThemeProperties::COLOR_FRAME, incognito), 0x80);
605 case ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BORDER:
606 return color_utils::AlphaBlend(GetColor(kLabelBackground, incognito),
607 SK_ColorBLACK, 230);
608 #endif
609 case ThemeProperties::COLOR_STATUS_BAR_TEXT: {
610 // A long time ago, we blended the toolbar and the tab text together to
611 // get the status bar text because, at the time, our text rendering in
612 // views couldn't do alpha blending. Even though this is no longer the
613 // case, this blending decision is built into the majority of themes that
614 // exist, and we must keep doing it.
615 SkColor toolbar_color =
616 GetColor(ThemeProperties::COLOR_TOOLBAR, incognito);
617 SkColor text_color = GetColor(ThemeProperties::COLOR_TAB_TEXT, incognito);
618 return SkColorSetARGB(
619 SkColorGetA(text_color),
620 (SkColorGetR(text_color) + SkColorGetR(toolbar_color)) / 2,
621 (SkColorGetG(text_color) + SkColorGetR(toolbar_color)) / 2,
622 (SkColorGetB(text_color) + SkColorGetR(toolbar_color)) / 2);
623 }
624 }
625
626 return ThemeProperties::GetDefaultColor(id, incognito);
627 } 636 }
628 637
629 int ThemeService::GetDisplayProperty(int id) const { 638 int ThemeService::GetDisplayProperty(int id) const {
630 int result = 0; 639 int result = 0;
631 if (theme_supplier_ && theme_supplier_->GetDisplayProperty(id, &result)) { 640 if (theme_supplier_ && theme_supplier_->GetDisplayProperty(id, &result)) {
632 return result; 641 return result;
633 } 642 }
634 643
635 switch (id) { 644 switch (id) {
636 case ThemeProperties::NTP_BACKGROUND_ALIGNMENT: 645 case ThemeProperties::NTP_BACKGROUND_ALIGNMENT:
637 return ThemeProperties::ALIGN_CENTER; 646 return ThemeProperties::ALIGN_CENTER;
638 647
639 case ThemeProperties::NTP_BACKGROUND_TILING: 648 case ThemeProperties::NTP_BACKGROUND_TILING:
640 return ThemeProperties::NO_REPEAT; 649 return ThemeProperties::NO_REPEAT;
641 650
642 case ThemeProperties::NTP_LOGO_ALTERNATE: { 651 case ThemeProperties::NTP_LOGO_ALTERNATE: {
643 if (UsingDefaultTheme() || UsingSystemTheme()) 652 if (UsingDefaultTheme() || UsingSystemTheme())
644 return 0; 653 return 0;
645 if (HasCustomImage(IDR_THEME_NTP_BACKGROUND)) 654 if (HasCustomImage(IDR_THEME_NTP_BACKGROUND))
646 return 1; 655 return 1;
647 return IsColorGrayscale( 656 return IsColorGrayscale(
648 GetColor(ThemeProperties::COLOR_NTP_BACKGROUND, false)) ? 0 : 1; 657 GetColor(ThemeProperties::COLOR_NTP_BACKGROUND, false)) ? 0 : 1;
649 } 658 }
650 659
651 default: 660 default:
652 return -1; 661 return -1;
653 } 662 }
654 } 663 }
655 664
656 bool ThemeService::ShouldUseNativeFrame() const {
657 if (HasCustomImage(IDR_THEME_FRAME))
658 return false;
659 #if defined(OS_WIN)
660 return ui::win::IsAeroGlassEnabled();
661 #else
662 return false;
663 #endif
664 }
665
666 bool ThemeService::HasCustomImage(int id) const {
667 return BrowserThemePack::IsPersistentImageID(id) && theme_supplier_ &&
668 theme_supplier_->HasCustomImage(id);
669 }
670
671 base::RefCountedMemory* ThemeService::GetRawData( 665 base::RefCountedMemory* ThemeService::GetRawData(
672 int id, 666 int id,
673 ui::ScaleFactor scale_factor) const { 667 ui::ScaleFactor scale_factor) const {
674 // Check to see whether we should substitute some images. 668 // Check to see whether we should substitute some images.
675 int ntp_alternate = GetDisplayProperty(ThemeProperties::NTP_LOGO_ALTERNATE); 669 int ntp_alternate = GetDisplayProperty(ThemeProperties::NTP_LOGO_ALTERNATE);
676 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) 670 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0)
677 id = IDR_PRODUCT_LOGO_WHITE; 671 id = IDR_PRODUCT_LOGO_WHITE;
678 672
679 base::RefCountedMemory* data = nullptr; 673 base::RefCountedMemory* data = nullptr;
680 if (theme_supplier_) 674 if (theme_supplier_)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 794
801 #if defined(ENABLE_SUPERVISED_USERS) 795 #if defined(ENABLE_SUPERVISED_USERS)
802 bool ThemeService::IsSupervisedUser() const { 796 bool ThemeService::IsSupervisedUser() const {
803 return profile_->IsSupervised(); 797 return profile_->IsSupervised();
804 } 798 }
805 799
806 void ThemeService::SetSupervisedUserTheme() { 800 void ThemeService::SetSupervisedUserTheme() {
807 SetCustomDefaultTheme(new SupervisedUserTheme); 801 SetCustomDefaultTheme(new SupervisedUserTheme);
808 } 802 }
809 #endif 803 #endif
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service.h ('k') | chrome/browser/themes/theme_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698