-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13124 from brave/fixed_dark_mode_omnibox_colors
Fixed wrong location bar/omnibox colors are used
- Loading branch information
Showing
5 changed files
with
130 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/themes/brave_theme_helper_utils.h" | ||
|
||
#include "base/numerics/safe_conversions.h" | ||
#include "chrome/browser/themes/theme_properties.h" | ||
#include "chrome/browser/ui/omnibox/omnibox_theme.h" | ||
#include "ui/gfx/color_palette.h" | ||
#include "ui/gfx/color_utils.h" | ||
#include "ui/native_theme/native_theme.h" | ||
|
||
namespace { | ||
|
||
// Location bar colors | ||
const SkColor kPrivateLocationBarBgBase = SkColorSetRGB(0x0B, 0x07, 0x24); | ||
const SkColor kDarkLocationBarBgBase = SkColorSetRGB(0x18, 0x1A, 0x21); | ||
const SkColor kDarkLocationBarHoverBg = SkColorSetRGB(0x23, 0x25, 0x2F); | ||
|
||
} // namespace | ||
|
||
SkColor GetLocationBarBackground(bool dark, bool priv, bool hover) { | ||
if (priv) { | ||
return hover ? color_utils::HSLShift(kPrivateLocationBarBgBase, | ||
{-1, -1, 0.54}) | ||
: kPrivateLocationBarBgBase; | ||
} | ||
|
||
if (dark) { | ||
return hover ? kDarkLocationBarHoverBg : kDarkLocationBarBgBase; | ||
} | ||
|
||
return hover ? color_utils::AlphaBlend(SK_ColorWHITE, | ||
SkColorSetRGB(0xf3, 0xf3, 0xf3), 0.7f) | ||
: SK_ColorWHITE; | ||
} | ||
|
||
// Omnibox result bg colors | ||
SkColor GetOmniboxResultBackground(int id, bool dark, bool priv) { | ||
// For high contrast, selected rows use inverted colors to stand out more. | ||
ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi(); | ||
bool high_contrast = | ||
native_theme && native_theme->UserHasContrastPreference(); | ||
OmniboxPartState state = OmniboxPartState::NORMAL; | ||
if (id == ThemeProperties::COLOR_OMNIBOX_RESULTS_BG_HOVERED) { | ||
state = OmniboxPartState::HOVERED; | ||
} else if (id == ThemeProperties::COLOR_OMNIBOX_RESULTS_BG_SELECTED) { | ||
state = OmniboxPartState::SELECTED; | ||
} | ||
|
||
SkColor color; | ||
if (priv) { | ||
color = high_contrast ? color_utils::HSLShift(kPrivateLocationBarBgBase, | ||
{-1, -1, 0.45}) | ||
: kPrivateLocationBarBgBase; | ||
} else if (dark) { | ||
color = high_contrast ? gfx::kGoogleGrey900 : kDarkLocationBarBgBase; | ||
} else { | ||
color = SK_ColorWHITE; | ||
} | ||
return color_utils::BlendTowardMaxContrast( | ||
color, base::ClampRound(GetOmniboxStateOpacity(state) * 0xff)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_THEMES_BRAVE_THEME_HELPER_UTILS_H_ | ||
#define BRAVE_BROWSER_THEMES_BRAVE_THEME_HELPER_UTILS_H_ | ||
|
||
#include "third_party/skia/include/core/SkColor.h" | ||
|
||
SkColor GetLocationBarBackground(bool dark, bool priv, bool hover); | ||
SkColor GetOmniboxResultBackground(int id, bool dark, bool priv); | ||
|
||
#endif // BRAVE_BROWSER_THEMES_BRAVE_THEME_HELPER_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters