summaryrefslogtreecommitdiff
path: root/chromium/ui/native_theme/common_theme.cc
blob: 5d675682b77ca0b381f0a39bb5af69dc5b4101c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/native_theme/common_theme.h"

#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/optional.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/overlay_scrollbar_constants_aura.h"

namespace ui {

namespace {

NativeTheme::SecurityChipColorId GetSecurityChipColorId(
    NativeTheme::ColorId color_id) {
  static const base::NoDestructor<
      base::flat_map<NativeTheme::ColorId, NativeTheme::SecurityChipColorId>>
      color_id_map({
          {NativeTheme::kColorId_CustomTabBarSecurityChipDefaultColor,
           NativeTheme::SecurityChipColorId::DEFAULT},
          {NativeTheme::kColorId_CustomTabBarSecurityChipSecureColor,
           NativeTheme::SecurityChipColorId::SECURE},
          {NativeTheme::kColorId_CustomTabBarSecurityChipWithCertColor,
           NativeTheme::SecurityChipColorId::SECURE_WITH_CERT},
          {NativeTheme::kColorId_CustomTabBarSecurityChipDangerousColor,
           NativeTheme::SecurityChipColorId::DANGEROUS},
      });
  return color_id_map->at(color_id);
}

base::Optional<SkColor> GetHighContrastColor(
    NativeTheme::ColorId color_id,
    NativeTheme::ColorScheme color_scheme) {
  switch (color_id) {
    case NativeTheme::kColorId_ButtonUncheckedColor:
    case NativeTheme::kColorId_MenuBorderColor:
    case NativeTheme::kColorId_MenuSeparatorColor:
    case NativeTheme::kColorId_SeparatorColor:
    case NativeTheme::kColorId_UnfocusedBorderColor:
    case NativeTheme::kColorId_TabBottomBorder:
      return color_scheme == NativeTheme::ColorScheme::kDark ? SK_ColorWHITE
                                                             : SK_ColorBLACK;
    case NativeTheme::kColorId_ButtonCheckedColor:
    case NativeTheme::kColorId_ButtonEnabledColor:
    case NativeTheme::kColorId_FocusedBorderColor:
    case NativeTheme::kColorId_ProminentButtonColor:
      return color_scheme == NativeTheme::ColorScheme::kDark
                 ? gfx::kGoogleBlue100
                 : gfx::kGoogleBlue900;
    default:
      return base::nullopt;
  }
}

base::Optional<SkColor> GetDarkSchemeColor(NativeTheme::ColorId color_id) {
  switch (color_id) {
    // Dialogs
    case NativeTheme::kColorId_WindowBackground:
    case NativeTheme::kColorId_ButtonColor:
    case NativeTheme::kColorId_DialogBackground:
    case NativeTheme::kColorId_BubbleBackground:
    case NativeTheme::kColorId_NotificationDefaultBackground:
      return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
    case NativeTheme::kColorId_AvatarIconGuest:
    case NativeTheme::kColorId_DialogForeground:
      return gfx::kGoogleGrey500;
    case NativeTheme::kColorId_BubbleFooterBackground:
      return SkColorSetRGB(0x32, 0x36, 0x39);
    case NativeTheme::kColorId_AvatarHeaderArt:
      return gfx::kGoogleGrey800;
    case NativeTheme::kColorId_AvatarIconIncognito:
      return gfx::kGoogleGrey200;

    // FocusableBorder
    case NativeTheme::kColorId_FocusedBorderColor:
      return SkColorSetA(gfx::kGoogleBlue300, 0x4D);
    case NativeTheme::kColorId_UnfocusedBorderColor:
      return gfx::kGoogleGrey800;

    // Button
    case NativeTheme::kColorId_ButtonBorderColor:
      return gfx::kGoogleGrey800;
    case NativeTheme::kColorId_ButtonCheckedColor:
    case NativeTheme::kColorId_ButtonEnabledColor:
    case NativeTheme::kColorId_ProminentButtonColor:
      return gfx::kGoogleBlue300;
    case NativeTheme::kColorId_ButtonHoverColor:
      return SkColorSetA(SK_ColorBLACK, 0x0A);
    case NativeTheme::kColorId_ButtonInkDropShadowColor:
      return SkColorSetA(SK_ColorBLACK, 0x7F);
    case NativeTheme::kColorId_ButtonInkDropFillColor:
    case NativeTheme::kColorId_ProminentButtonInkDropFillColor:
      return SkColorSetA(SK_ColorWHITE, 0x0A);
    case NativeTheme::kColorId_ProminentButtonInkDropShadowColor:
      return SkColorSetA(gfx::kGoogleBlue300, 0x7F);
    case NativeTheme::kColorId_ProminentButtonHoverColor:
      return SkColorSetA(SK_ColorWHITE, 0x0A);
    case NativeTheme::kColorId_ButtonUncheckedColor:
      return gfx::kGoogleGrey500;
    case NativeTheme::kColorId_TextOnProminentButtonColor:
      return gfx::kGoogleGrey900;
    case NativeTheme::kColorId_PaddedButtonInkDropColor:
      return SK_ColorWHITE;

    // MenuItem
    case NativeTheme::kColorId_HighlightedMenuItemForegroundColor:
    case NativeTheme::kColorId_MenuDropIndicator:
      return gfx::kGoogleGrey200;
    case NativeTheme::kColorId_MenuBorderColor:
    case NativeTheme::kColorId_MenuSeparatorColor:
      return gfx::kGoogleGrey800;
    case NativeTheme::kColorId_HighlightedMenuItemBackgroundColor:
      return SkColorSetRGB(0x32, 0x36, 0x39);
    case NativeTheme::kColorId_MenuItemInitialAlertBackgroundColor:
      return SkColorSetA(gfx::kGoogleBlue300, 0x4D);
    case NativeTheme::kColorId_MenuItemTargetAlertBackgroundColor:
      return SkColorSetA(gfx::kGoogleBlue300, 0x1A);
    case NativeTheme::kColorId_MenuItemMinorTextColor:
      return gfx::kGoogleGrey500;

    // Custom frame view
    case NativeTheme::kColorId_CustomFrameActiveColor:
      return gfx::kGoogleGrey900;
    case NativeTheme::kColorId_CustomFrameInactiveColor:
      return gfx::kGoogleGrey800;

    // Custom tab bar
    case NativeTheme::kColorId_CustomTabBarBackgroundColor:
      return gfx::kGoogleGrey900;

    // Dropdown
    case NativeTheme::kColorId_DropdownBackgroundColor:
      return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
    case NativeTheme::kColorId_DropdownForegroundColor:
      return gfx::kGoogleGrey200;
    case NativeTheme::kColorId_DropdownSelectedForegroundColor:
      return gfx::kGoogleGrey200;

    // Label
    case NativeTheme::kColorId_LabelEnabledColor:
    case NativeTheme::kColorId_LabelTextSelectionColor:
      return gfx::kGoogleGrey200;
    case NativeTheme::kColorId_LabelSecondaryColor:
      return gfx::kGoogleGrey500;
    case NativeTheme::kColorId_LabelTextSelectionBackgroundFocused:
      return gfx::kGoogleBlue800;

    // Link
    case NativeTheme::kColorId_LinkEnabled:
    case NativeTheme::kColorId_LinkPressed:
      return gfx::kGoogleBlue300;

    // Separator
    case NativeTheme::kColorId_SeparatorColor:
      return gfx::kGoogleGrey800;

    // TabbedPane
    case NativeTheme::kColorId_TabTitleColorActive:
    case NativeTheme::kColorId_TabSelectedBorderColor:
      return gfx::kGoogleBlue300;
    case NativeTheme::kColorId_TabTitleColorInactive:
      return gfx::kGoogleGrey500;
    case NativeTheme::kColorId_TabBottomBorder:
      return gfx::kGoogleGrey800;
    case NativeTheme::kColorId_TabHighlightBackground:
      return gfx::kGoogleGrey800;
    case NativeTheme::kColorId_TabHighlightFocusedBackground:
      return SkColorSetRGB(0x32, 0x36, 0x39);

    // Table
    case NativeTheme::kColorId_TableBackground:
    case NativeTheme::kColorId_TableBackgroundAlternate:
      return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
    case NativeTheme::kColorId_TableText:
    case NativeTheme::kColorId_TableSelectedText:
    case NativeTheme::kColorId_TableSelectedTextUnfocused:
      return gfx::kGoogleGrey200;

    // Textfield
    case NativeTheme::kColorId_TextfieldDefaultColor:
    case NativeTheme::kColorId_TextfieldSelectionColor:
      return gfx::kGoogleGrey200;
    case NativeTheme::kColorId_TextfieldReadOnlyBackground: {
      return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
    }
    case NativeTheme::kColorId_TextfieldSelectionBackgroundFocused:
      return gfx::kGoogleBlue800;

    // Tooltip
    case NativeTheme::kColorId_TooltipIcon:
      return SkColorSetA(gfx::kGoogleGrey200, 0xBD);
    case NativeTheme::kColorId_TooltipIconHovered:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_TooltipText:
      return SkColorSetA(gfx::kGoogleGrey200, 0xDE);

    // Tree
    case NativeTheme::kColorId_TreeBackground:
      return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
    case NativeTheme::kColorId_TreeText:
    case NativeTheme::kColorId_TreeSelectedText:
    case NativeTheme::kColorId_TreeSelectedTextUnfocused:
      return gfx::kGoogleGrey200;

    // Material spinner/throbber
    case NativeTheme::kColorId_ThrobberSpinningColor:
      return gfx::kGoogleBlue300;

    case NativeTheme::kColorId_BubbleBorder:
      return gfx::kGoogleGrey800;

    case NativeTheme::kColorId_FootnoteContainerBorder:
      return gfx::kGoogleGrey900;

    // Alert icon colors
    case NativeTheme::kColorId_AlertSeverityLow:
      return gfx::kGoogleGreen300;
    case NativeTheme::kColorId_AlertSeverityMedium:
      return gfx::kGoogleYellow300;
    case NativeTheme::kColorId_AlertSeverityHigh:
      return gfx::kGoogleRed300;

    case NativeTheme::kColorId_MenuIconColor:
    case NativeTheme::kColorId_DefaultIconColor:
      return gfx::kGoogleGrey500;
    default:
      return base::nullopt;
  }
}

SkColor GetDefaultColor(NativeTheme::ColorId color_id,
                        const NativeTheme* base_theme,
                        NativeTheme::ColorScheme color_scheme) {
  constexpr SkColor kPrimaryTextColor = gfx::kGoogleGrey900;

  switch (color_id) {
    // Dialogs
    case NativeTheme::kColorId_WindowBackground:
    case NativeTheme::kColorId_ButtonColor:
    case NativeTheme::kColorId_DialogBackground:
    case NativeTheme::kColorId_BubbleBackground:
    case NativeTheme::kColorId_NotificationDefaultBackground:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_AvatarHeaderArt:
      return gfx::kGoogleGrey300;
    case NativeTheme::kColorId_AvatarIconIncognito:
      return kPrimaryTextColor;
    case NativeTheme::kColorId_AvatarIconGuest:
    case NativeTheme::kColorId_DialogForeground:
      return gfx::kGoogleGrey700;
    case NativeTheme::kColorId_BubbleFooterBackground:
      return gfx::kGoogleGrey050;

    // Buttons
    case NativeTheme::kColorId_ButtonCheckedColor:
    case NativeTheme::kColorId_ButtonEnabledColor:
      return gfx::kGoogleBlue600;
    case NativeTheme::kColorId_ButtonInkDropShadowColor:
      return SkColorSetA(SK_ColorBLACK, 0x1A);
    case NativeTheme::kColorId_ButtonHoverColor:
      return SkColorSetA(SK_ColorBLACK, 0x05);
    case NativeTheme::kColorId_ButtonInkDropFillColor:
      return SkColorSetA(SK_ColorWHITE, 0x05);
    case NativeTheme::kColorId_ProminentButtonInkDropShadowColor:
      return SkColorSetA(SK_ColorBLACK, 0x3D);
    case NativeTheme::kColorId_ProminentButtonHoverColor:
      return SkColorSetA(SK_ColorWHITE, 0x0D);
    case NativeTheme::kColorId_ProminentButtonInkDropFillColor:
      return SkColorSetA(SK_ColorWHITE, 0x0D);
    case NativeTheme::kColorId_ProminentButtonFocusedColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_ProminentButtonColor, color_scheme);
      return color_utils::BlendForMinContrast(bg, bg, base::nullopt, 1.3f)
          .color;
    }
    case NativeTheme::kColorId_ProminentButtonColor:
      return gfx::kGoogleBlue600;
    case NativeTheme::kColorId_TextOnProminentButtonColor:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_ButtonUncheckedColor:
      return gfx::kGoogleGrey700;
    case NativeTheme::kColorId_ButtonDisabledColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_ButtonColor, color_scheme);
      const SkColor fg = base_theme->GetSystemColor(
          NativeTheme::kColorId_LabelEnabledColor, color_scheme);
      return color_utils::BlendForMinContrast(gfx::kGoogleGrey600, bg, fg)
          .color;
    }
    case NativeTheme::kColorId_ProminentButtonDisabledColor:
    case NativeTheme::kColorId_DisabledButtonBorderColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_ButtonColor, color_scheme);
      return color_utils::BlendForMinContrast(bg, bg, base::nullopt, 1.2f)
          .color;
    }
    case NativeTheme::kColorId_ButtonBorderColor:
      return gfx::kGoogleGrey300;
    case NativeTheme::kColorId_PaddedButtonInkDropColor:
      return gfx::kGoogleGrey900;

    // ToggleButton
    case NativeTheme::kColorId_ToggleButtonShadowColor:
      return SkColorSetA(
          base_theme->GetSystemColor(NativeTheme::kColorId_LabelEnabledColor,
                                     color_scheme),
          0x99);
    case ui::NativeTheme::kColorId_ToggleButtonTrackColorOff:
    case ui::NativeTheme::kColorId_ToggleButtonTrackColorOn: {
      const ui::NativeTheme::ColorId base_color_id =
          color_id == ui::NativeTheme::kColorId_ToggleButtonTrackColorOff
              ? ui::NativeTheme::kColorId_LabelEnabledColor
              : ui::NativeTheme::kColorId_ProminentButtonColor;
      return SkColorSetA(
          base_theme->GetSystemColor(base_color_id, color_scheme), 0x66);
    }

    // MenuItem
    case NativeTheme::kColorId_EnabledMenuItemForegroundColor:
      return base_theme->GetSystemColor(
          NativeTheme::kColorId_DropdownForegroundColor, color_scheme);
    case NativeTheme::kColorId_SelectedMenuItemForegroundColor:
      return base_theme->GetSystemColor(
          NativeTheme::kColorId_DropdownSelectedForegroundColor, color_scheme);
    case NativeTheme::kColorId_HighlightedMenuItemForegroundColor:
    case NativeTheme::kColorId_MenuDropIndicator:
      return kPrimaryTextColor;
    case NativeTheme::kColorId_FocusedMenuItemBackgroundColor:
      return base_theme->GetSystemColor(
          NativeTheme::kColorId_DropdownSelectedBackgroundColor, color_scheme);
    case NativeTheme::kColorId_MenuBorderColor:
    case NativeTheme::kColorId_MenuSeparatorColor:
      return gfx::kGoogleGrey300;
    case NativeTheme::kColorId_MenuBackgroundColor:
      return base_theme->GetSystemColor(
          NativeTheme::kColorId_DropdownBackgroundColor, color_scheme);
    case NativeTheme::kColorId_DisabledMenuItemForegroundColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_MenuBackgroundColor, color_scheme);
      const SkColor fg = base_theme->GetSystemColor(
          NativeTheme::kColorId_EnabledMenuItemForegroundColor, color_scheme);
      return color_utils::BlendForMinContrast(gfx::kGoogleGrey600, bg, fg)
          .color;
    }
    case NativeTheme::kColorId_MenuItemMinorTextColor:
      return gfx::kGoogleGrey700;
    case NativeTheme::kColorId_HighlightedMenuItemBackgroundColor:
      return gfx::kGoogleGrey050;
    case NativeTheme::kColorId_MenuItemInitialAlertBackgroundColor:
      return SkColorSetA(gfx::kGoogleBlue600, 0x4D);
    case NativeTheme::kColorId_MenuItemTargetAlertBackgroundColor:
      return SkColorSetA(gfx::kGoogleBlue600, 0x1A);

    // Custom frame view
    case NativeTheme::kColorId_CustomFrameActiveColor:
      return SkColorSetRGB(0xDE, 0xE1, 0xE6);
    case NativeTheme::kColorId_CustomFrameInactiveColor:
      return SkColorSetRGB(0xE7, 0xEA, 0xED);

    // Custom tab bar
    case NativeTheme::kColorId_CustomTabBarBackgroundColor:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_CustomTabBarForegroundColor:
      return color_utils::GetColorWithMaxContrast(base_theme->GetSystemColor(
          NativeTheme::kColorId_CustomTabBarBackgroundColor, color_scheme));
    case NativeTheme::kColorId_CustomTabBarSecurityChipWithCertColor:
    case NativeTheme::kColorId_CustomTabBarSecurityChipSecureColor:
    case NativeTheme::kColorId_CustomTabBarSecurityChipDefaultColor:
    case NativeTheme::kColorId_CustomTabBarSecurityChipDangerousColor: {
      const SkColor fg = base_theme->GetSystemColor(
          NativeTheme::kColorId_CustomTabBarForegroundColor, color_scheme);
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_CustomTabBarBackgroundColor, color_scheme);
      return GetSecurityChipColor(GetSecurityChipColorId(color_id), fg, bg);
    }

    // Dropdown
    case NativeTheme::kColorId_DropdownBackgroundColor:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_DropdownForegroundColor:
      return kPrimaryTextColor;
    case NativeTheme::kColorId_DropdownSelectedBackgroundColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_MenuBackgroundColor, color_scheme);
      return color_utils::BlendForMinContrast(bg, bg, base::nullopt, 1.67f)
          .color;
    }
    case NativeTheme::kColorId_DropdownSelectedForegroundColor:
      return kPrimaryTextColor;

    // Label
    case NativeTheme::kColorId_LabelEnabledColor:
    case NativeTheme::kColorId_LabelTextSelectionColor:
      return kPrimaryTextColor;
    case NativeTheme::kColorId_LabelDisabledColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_DialogBackground, color_scheme);
      const SkColor fg = base_theme->GetSystemColor(
          NativeTheme::kColorId_LabelEnabledColor, color_scheme);
      return color_utils::BlendForMinContrast(gfx::kGoogleGrey600, bg, fg)
          .color;
    }
    case NativeTheme::kColorId_LabelSecondaryColor:
      return gfx::kGoogleGrey700;
    case NativeTheme::kColorId_LabelTextSelectionBackgroundFocused:
      return gfx::kGoogleBlue200;

    // Link
    case NativeTheme::kColorId_LinkDisabled: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_DialogBackground, color_scheme);
      const SkColor fg = base_theme->GetSystemColor(
          NativeTheme::kColorId_LabelEnabledColor, color_scheme);
      return color_utils::BlendForMinContrast(gfx::kGoogleGrey600, bg, fg)
          .color;
    }
    case NativeTheme::kColorId_LinkEnabled:
    case NativeTheme::kColorId_LinkPressed:
      return gfx::kGoogleBlue600;

    // Notification view
    case NativeTheme::kColorId_NotificationPlaceholderIconColor:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_NotificationActionsRowBackground:
    case NativeTheme::kColorId_NotificationInlineSettingsBackground: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_NotificationDefaultBackground, color_scheme);
      // The alpha value here (0x14) is chosen to generate 0xEEE from 0xFFF.
      return color_utils::BlendTowardMaxContrast(bg, 0x14);
    }
    case NativeTheme::kColorId_NotificationLargeImageBackground: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_NotificationDefaultBackground, color_scheme);
      // The alpha value here (0x0C) is chosen to generate 0xF5F5F5 from 0xFFF.
      return color_utils::BlendTowardMaxContrast(bg, 0x0C);
    }
    case NativeTheme::kColorId_NotificationEmptyPlaceholderIconColor:
      return SkColorSetA(SK_ColorWHITE, 0x60);
    case NativeTheme::kColorId_NotificationEmptyPlaceholderTextColor:
      return SkColorSetA(SK_ColorWHITE, gfx::kDisabledControlAlpha);
    case NativeTheme::kColorId_NotificationInkDropBase:
      return gfx::kGoogleBlue600;
#if defined(OS_CHROMEOS)
    case NativeTheme::kColorId_NotificationButtonBackground:
      return SkColorSetA(SK_ColorWHITE, 0.9 * 0xff);
#endif
    case NativeTheme::kColorId_NotificationDefaultAccentColor:
      return gfx::kChromeIconGrey;

    // Scrollbar
    case NativeTheme::kColorId_OverlayScrollbarThumbBackground:
      return SK_ColorBLACK;
    case NativeTheme::kColorId_OverlayScrollbarThumbForeground:
      return SkColorSetA(SK_ColorWHITE, (kOverlayScrollbarStrokeNormalAlpha /
                                         kOverlayScrollbarThumbNormalAlpha) *
                                            SK_AlphaOPAQUE);

    // Slider
    case NativeTheme::kColorId_SliderThumbDefault:
      return SkColorSetARGB(0xFF, 0x25, 0x81, 0xDF);
    case NativeTheme::kColorId_SliderTroughDefault:
      return SkColorSetARGB(0x40, 0x25, 0x81, 0xDF);
    case NativeTheme::kColorId_SliderThumbMinimal:
      return SkColorSetARGB(0x6E, 0xF1, 0xF3, 0xF4);
    case NativeTheme::kColorId_SliderTroughMinimal:
      return SkColorSetARGB(0x19, 0xF1, 0xF3, 0xF4);

    // Separator
    case NativeTheme::kColorId_SeparatorColor:
      return gfx::kGoogleGrey300;

    // TabbedPane
    case NativeTheme::kColorId_TabTitleColorActive:
    case NativeTheme::kColorId_TabSelectedBorderColor:
      return gfx::kGoogleBlue600;
    case NativeTheme::kColorId_TabTitleColorInactive:
      return gfx::kGoogleGrey700;
    case NativeTheme::kColorId_TabBottomBorder:
      return gfx::kGoogleGrey300;
    case NativeTheme::kColorId_TabHighlightBackground:
      return gfx::kGoogleBlue050;
    case NativeTheme::kColorId_TabHighlightFocusedBackground:
      return gfx::kGoogleBlue100;

    // Textfield
    case NativeTheme::kColorId_TextfieldDefaultColor:
    case NativeTheme::kColorId_TextfieldSelectionColor:
      return kPrimaryTextColor;
    case NativeTheme::kColorId_TextfieldDefaultBackground: {
      const SkColor fg = base_theme->GetSystemColor(
          NativeTheme::kColorId_TextfieldDefaultColor, color_scheme);
      return color_utils::GetColorWithMaxContrast(fg);
    }
    case NativeTheme::kColorId_TextfieldReadOnlyBackground:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_TextfieldPlaceholderColor:
    case NativeTheme::kColorId_TextfieldReadOnlyColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_TextfieldReadOnlyBackground, color_scheme);
      const SkColor fg = base_theme->GetSystemColor(
          NativeTheme::kColorId_TextfieldDefaultColor, color_scheme);
      return color_utils::BlendForMinContrast(gfx::kGoogleGrey600, bg, fg)
          .color;
    }
    case NativeTheme::kColorId_TextfieldSelectionBackgroundFocused:
      return gfx::kGoogleBlue200;

    // Tooltip
    case NativeTheme::kColorId_TooltipBackground: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_WindowBackground, color_scheme);
      return SkColorSetA(bg, 0xCC);
    }
    case NativeTheme::kColorId_TooltipIcon:
      return SkColorSetA(gfx::kGoogleGrey800, 0xBD);
    case NativeTheme::kColorId_TooltipIconHovered:
      return SkColorSetA(SK_ColorBLACK, 0xBD);
    case NativeTheme::kColorId_TooltipText:
      return SkColorSetA(kPrimaryTextColor, 0xDE);

    // Tree
    case NativeTheme::kColorId_TreeBackground:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_TreeText:
    case NativeTheme::kColorId_TreeSelectedText:
    case NativeTheme::kColorId_TreeSelectedTextUnfocused:
      return kPrimaryTextColor;
    case NativeTheme::kColorId_TreeSelectionBackgroundFocused:
    case NativeTheme::kColorId_TreeSelectionBackgroundUnfocused: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_TreeBackground, color_scheme);
      return color_utils::BlendForMinContrast(bg, bg, base::nullopt, 1.67f)
          .color;
    }

    // Table
    case NativeTheme::kColorId_TableBackground:
    case NativeTheme::kColorId_TableBackgroundAlternate:
      return SK_ColorWHITE;
    case NativeTheme::kColorId_TableText:
    case NativeTheme::kColorId_TableSelectedText:
    case NativeTheme::kColorId_TableSelectedTextUnfocused:
      return kPrimaryTextColor;
    case NativeTheme::kColorId_TableSelectionBackgroundFocused:
    case NativeTheme::kColorId_TableSelectionBackgroundUnfocused:
    case NativeTheme::kColorId_TableGroupingIndicatorColor: {
      const SkColor bg = base_theme->GetSystemColor(
          NativeTheme::kColorId_TableBackground, color_scheme);
      return color_utils::BlendForMinContrast(bg, bg, base::nullopt, 1.67f)
          .color;
    }

    // Table Header
    case NativeTheme::kColorId_TableHeaderText:
      return base_theme->GetSystemColor(NativeTheme::kColorId_TableText,
                                        color_scheme);
    case NativeTheme::kColorId_TableHeaderBackground:
      return base_theme->GetSystemColor(NativeTheme::kColorId_TableBackground,
                                        color_scheme);
    case NativeTheme::kColorId_TableHeaderSeparator:
      return base_theme->GetSystemColor(NativeTheme::kColorId_MenuBorderColor,
                                        color_scheme);

    // FocusableBorder
    case NativeTheme::kColorId_FocusedBorderColor:
      return SkColorSetA(gfx::kGoogleBlue600, 0x4D);
    case NativeTheme::kColorId_UnfocusedBorderColor:
      return gfx::kGoogleGrey300;

    // Material spinner/throbber
    case NativeTheme::kColorId_ThrobberSpinningColor:
      return gfx::kGoogleBlue600;
    case NativeTheme::kColorId_ThrobberWaitingColor:
      return SkColorSetRGB(0xA6, 0xA6, 0xA6);
    case NativeTheme::kColorId_ThrobberLightColor:
      return SkColorSetRGB(0xF4, 0xF8, 0xFD);

    // Alert icon colors
    case NativeTheme::kColorId_AlertSeverityLow:
      return gfx::kGoogleGreen700;
    case NativeTheme::kColorId_AlertSeverityMedium:
      return gfx::kGoogleYellow700;
    case NativeTheme::kColorId_AlertSeverityHigh:
      return gfx::kGoogleRed600;

    case NativeTheme::kColorId_FootnoteContainerBorder:
      return gfx::kGoogleGrey200;

    case NativeTheme::kColorId_MenuIconColor:
    case NativeTheme::kColorId_DefaultIconColor:
      return gfx::kGoogleGrey700;
    case NativeTheme::kColorId_DisabledIconColor:
      return SkColorSetA(
          base_theme->GetSystemColor(NativeTheme::kColorId_DefaultIconColor),
          gfx::kDisabledControlAlpha);

    // Sync info container
    case NativeTheme::kColorId_SyncInfoContainerPaused:
      return SkColorSetA(base_theme->GetSystemColor(
                             NativeTheme::kColorId_ProminentButtonColor),
                         16);
    case NativeTheme::kColorId_SyncInfoContainerError:
      return SkColorSetA(
          base_theme->GetSystemColor(NativeTheme::kColorId_AlertSeverityHigh),
          16);
    case NativeTheme::kColorId_SyncInfoContainerNoPrimaryAccount:
      return base_theme->GetSystemColor(
          NativeTheme::kColorId_BubbleFooterBackground);

    case NativeTheme::kColorId_BubbleBorder:
      return gfx::kGoogleGrey300;

    case NativeTheme::kColorId_NumColors:
      // Keeping the kColorId_NumColors case instead of using the default case
      // allows ColorId additions to trigger compile error for an incomplete
      // switch enumeration.
      NOTREACHED();
      return gfx::kPlaceholderColor;
  }
}

}  // namespace

SkColor GetSecurityChipColor(NativeTheme::SecurityChipColorId chip_color_id,
                             SkColor fg,
                             SkColor bg,
                             bool high_contrast) {
  const bool dark = color_utils::IsDark(bg);
  const auto blend_for_min_contrast = [&](SkColor fg, SkColor bg,
                                          base::Optional<SkColor> hc_fg =
                                              base::nullopt) {
    const float ratio =
        high_contrast ? 6.0f : color_utils::kMinimumReadableContrastRatio;
    return color_utils::BlendForMinContrast(fg, bg, hc_fg, ratio).color;
  };
  const auto security_chip_color = [&](SkColor color) {
    return blend_for_min_contrast(color, bg);
  };

  switch (chip_color_id) {
    case NativeTheme::SecurityChipColorId::DEFAULT:
    case NativeTheme::SecurityChipColorId::SECURE:
      return dark
                 ? color_utils::BlendTowardMaxContrast(fg, 0x18)
                 : security_chip_color(color_utils::DeriveDefaultIconColor(fg));
    case NativeTheme::SecurityChipColorId::DANGEROUS:
      return dark ? color_utils::BlendTowardMaxContrast(fg, 0x18)
                  : security_chip_color(gfx::kGoogleRed600);
    case NativeTheme::SecurityChipColorId::SECURE_WITH_CERT:
      return blend_for_min_contrast(fg, fg, blend_for_min_contrast(bg, bg));
    default:
      NOTREACHED();
      return gfx::kPlaceholderColor;
  }
}

SkColor GetAuraColor(NativeTheme::ColorId color_id,
                     const NativeTheme* base_theme,
                     NativeTheme::ColorScheme color_scheme) {
  if (color_scheme == NativeTheme::ColorScheme::kDefault)
    color_scheme = base_theme->GetDefaultSystemColorScheme();

  // High contrast overrides the normal colors for certain ColorIds to be much
  // darker or lighter.
  if (base_theme->UsesHighContrastColors()) {
    base::Optional<SkColor> color =
        GetHighContrastColor(color_id, color_scheme);
    if (color.has_value())
      return color.value();
  }

  if (color_scheme == NativeTheme::ColorScheme::kDark) {
    base::Optional<SkColor> color = GetDarkSchemeColor(color_id);
    if (color.has_value())
      return color.value();
  }

  return GetDefaultColor(color_id, base_theme, color_scheme);
}

void CommonThemePaintMenuItemBackground(
    const NativeTheme* theme,
    cc::PaintCanvas* canvas,
    NativeTheme::State state,
    const gfx::Rect& rect,
    const NativeTheme::MenuItemExtraParams& menu_item,
    NativeTheme::ColorScheme color_scheme) {
  cc::PaintFlags flags;
  switch (state) {
    case NativeTheme::kNormal:
    case NativeTheme::kDisabled:
      flags.setColor(theme->GetSystemColor(
          NativeTheme::kColorId_MenuBackgroundColor, color_scheme));
      break;
    case NativeTheme::kHovered:
      flags.setColor(theme->GetSystemColor(
          NativeTheme::kColorId_FocusedMenuItemBackgroundColor, color_scheme));
      break;
    default:
      NOTREACHED() << "Invalid state " << state;
      break;
  }
  if (menu_item.corner_radius > 0) {
    const SkScalar radius = SkIntToScalar(menu_item.corner_radius);
    canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, flags);
    return;
  }
  canvas->drawRect(gfx::RectToSkRect(rect), flags);
}

}  // namespace ui