Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify color for focus ring #476

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions browser/ui/views/frame/brave_browser_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ BraveBrowserFrame::~BraveBrowserFrame() {
}

const ui::NativeTheme* BraveBrowserFrame::GetNativeTheme() const {
// Gets the platform-specific override for NativeTheme,
// unless we're in dark mode in which case get cross-platform
// dark theme.
// TODO: Have platform-specific version of dark theme too.
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
BraveThemeType active_builtin_theme =
BraveThemeService::GetActiveBraveThemeType(
Expand All @@ -28,5 +32,7 @@ const ui::NativeTheme* BraveBrowserFrame::GetNativeTheme() const {
return ui::NativeThemeDarkAura::instance();
}
#endif
// Each platform will implement ui::NativeTheme::GetInstanceForNativeUi
// separately, which Widget::GetNativeTheme calls.
return views::Widget::GetNativeTheme();
}
49 changes: 49 additions & 0 deletions chromium_src/ui/views/controls/focus_ring.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* 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 "base/no_destructor.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/color_palette.h"

// include header first so that GetNativeTheme redefine doesn't flow to View
#include "ui/views/controls/focus_ring.h"

// Override the Focus Ring's color.
// In Chromium, this is specified via platform-specfic native theme,
// using kColorId_FocusedBorderColor. However, only macOS Light native theme
// overrides this. Since we do not have a Brave version of either
// platform-specific, or common versions, and we only want to override a single
// color, we use this micro-theme for the FocusRingView.
namespace {

class FocusRingTheme {
public:
SkColor GetSystemColor(int id) {
// At the time of implementation, only two Color IDs were possible.
// If this changes, consider overriding NativeTheme, or moving to
// ThemeProperties.
DCHECK(id == ui::NativeTheme::kColorId_FocusedBorderColor ||
id == ui::NativeTheme::kColorId_AlertSeverityHigh);
// Must be colors that are OK on dark or light bg since this is
// a very simplistic implementation.
switch (id) {
case ui::NativeTheme::kColorId_FocusedBorderColor:
return SkColorSetRGB(0xfb, 0x54, 0x2b);
case ui::NativeTheme::kColorId_AlertSeverityHigh:
return SkColorSetRGB(0xf4, 0x34, 0x05);
}
return gfx::kPlaceholderColor;
}
};

FocusRingTheme* GetFocusRingTheme() {
static base::NoDestructor<FocusRingTheme> instance;
return instance.get();
}

}

#define GetNativeTheme GetFocusRingTheme
#include "../../../../ui/views/controls/focus_ring.cc"
#undef GetNativeTheme