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

OS(MacOS/Windows) theme controls brave theme #1805

Merged
merged 6 commits into from
Mar 13, 2019
Merged

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Feb 28, 2019

Please see each commit's log.
Fix brave/brave-browser#1189
Fix brave/brave-browser#1289
Fix brave/brave-browser#3708

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Verified that all lint errors/warnings are resolved (npm run lint)
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Yes or QA/No) to include the closed issue in milestone

Test Plan:

yarn test brave_browser_tests --filter=BraveThemeService*
yarn test brave_unit_tests --filter=BraveThemeServiceTest*

Manual test step

  1. Launch Browser
  2. Check theme settings have three options (Same as MacOS, Dark, Light)
  3. Check Same as MacOS applies MacOS theme to brave theme
  4. Check Dark/Light works independently with MacOS theme.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

@simonhong simonhong added this to the 0.63.x - Nightly milestone Feb 28, 2019
@simonhong simonhong self-assigned this Feb 28, 2019
@simonhong simonhong force-pushed the brave_theme_service branch 4 times, most recently from cb13d3f to 2ae8d60 Compare March 1, 2019 00:26
@simonhong simonhong changed the title WIP: OS theme controls brave theme MacOS theme controls brave theme Mar 1, 2019
@simonhong simonhong requested a review from petemill March 1, 2019 00:33
@simonhong
Copy link
Member Author

simonhong commented Mar 1, 2019

@petemill I think implementation is ready to review on MacOS/Windows. (lint commit is not yet pushed)
This PR covers all requirements that you told me in DM.
With changing of ui_base_features.cc like below, you can test this PR.
const base::Feature kDarkMode = {"DarkMode", base::FEATURE_ENABLED_BY_DEFAULT};
PTAL!

@simonhong simonhong marked this pull request as ready for review March 1, 2019 00:35
@simonhong simonhong force-pushed the brave_theme_service branch 2 times, most recently from 6db26e0 to b23f40f Compare March 1, 2019 03:47
@simonhong simonhong changed the title MacOS theme controls brave theme OS(MacOS/Windows) theme controls brave theme Mar 1, 2019
@petemill
Copy link
Member

petemill commented Mar 5, 2019

@simonhong this is awesome. Couple of points of feedback from usage so far on macOS 10.14 (supports dark mode):

  1. If I choose Brave's light theme but have macOS dark theme, we're still:

    • a. Styling Chromium-controlled components dark e.g. Popup windows, Main Menu (see below)
    • b. Using OS-controlled components in dark mode e.g. context menu

    I assume it's not too much effort to fix 1.a. but is it possible to fix 1.b? If not maybe we should remove the ability to change away from 'Same as macOS'

  2. When changing OS theme from dark to light, Brave does not change until the window is focused, whereas other apps (including Chrome Canary) changes immediately. Are we missing hooking in to an event when the OS theme changes?

Screenshots of examples

1.a

image

1.b

image

2.

image

@simonhong
Copy link
Member Author

@petemill
About 1, brave/brave-browser#1289 is the issue for it and it is my today's task. I think it's better to include that fix in this PR also.
For 2, Nice catch! I didn't test os theme change with Same as macOS. I'll check it also.
Thanks for review!

@simonhong
Copy link
Member Author

simonhong commented Mar 6, 2019

Issue 2 is fixed. but 1 is still in the dark.

To avoid inconsistency between brave theme and ui element(ex, menu) on MacOS, I tried to set appearance manually to NSApplication. Then, this works fine with light or dark mode but doesn't work with os theme mode. After set it manually, appearance isn't reverted to system theme even if os theme is changed. needs more study how to do it..

Found the solution how to reset manually set theme. (set nil to appearance)
https://developer.apple.com/documentation/appkit/nsapplication/2967170-appearance?language=objc
Seems works well! :)

@simonhong
Copy link
Member Author

@petemill Implementation is finished! :) Will request review when tests are ready!

@simonhong simonhong force-pushed the brave_theme_service branch 5 times, most recently from 89849ad to cc62fc0 Compare March 7, 2019 00:21
@simonhong
Copy link
Member Author

simonhong commented Mar 7, 2019

All issues about dark theme on MacOS are resolved.
Moving to Windows 10.

Issue 2 is also resolved on Win10. But Issue 1 would not be fixed easily in browser-side because Win10 doesn't support per-application theme.
So, when dark mode is enabled on Windows, only Same as Windows option has consistent theme between brave theme and base UI element. Other options could see issue 1 when system theme and brave theme is different.

GetActiveBraveThemeType(profile()) == BraveThemeType::BRAVE_THEME_TYPE_LIGHT
? ui::NativeThemeDarkAura::instance()->NotifyObservers()
: ui::NativeTheme::GetInstanceForNativeUi()->NotifyObservers();

NotifyThemeChanged();
Copy link
Member Author

@simonhong simonhong Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary call. above notifying does all things.

@simonhong
Copy link
Member Author

@petemill Ready to review again. PTAL!

@simonhong
Copy link
Member Author

kindly ping..

With this refactoring, webui and extension apis get more simpler
and we can add system theme support more easily.
And each menu item's localization is supported.
Also, GetUserPreferredBraveThemeType() and GetActiveBraveThemeType()
methods are unified with GetActiveBraveThemeType().
Apply OS theme to brave theme when default theme is used or
user selected "Same as MacOS" menu in settings.
Other options(Dark/Light) works independently with system theme.
Brave on linux is not yet supported.
Change brave theme properly when user changes os theme during the runtime.
NativeThemeMac notifies to proper theme observers.
If user selects light or dark, brave theme and base UI elements such as
dialog or menu should use same theme.
To achieve this, we override os theme with brave theme type.
On Windows, brave theme is changed properly when user changes app mode
by settings when user chooses "Same as Windows" option.
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great @simonhong! Review passed on macOS. Just waiting for successful Windows 10 and 7 builds in order to test there.

In addition to the tests I specified above, I tested upgrade from 0.63.4 with two scenarios:

  1. User had not previously changed from default theme. This PR successfully changed the default to 'Same as macOS'.
  2. User had previously changed theme explicitly to Light or Dark. This PR successfully maintained that preference.

I noticed that brave/brave-browser#3708 is fixed, perhaps also by this PR.

Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. Windows needs a lot of work since:

  • The menus have dark text on dark background
  • The LocationBar theme does not change when changing OS theme

But since we're not enabled on Windows (disabled via ui_base_features in Brave and upstream) and some of the issues there will be solved by upstream, we're good to go since:

  • The 'same as OS' feature works great on macOS 10.14
  • The old Light / Dark / Default-per-channel functionality still works on non-macOS and macOS < 10.14

@simonhong
Copy link
Member Author

@petemill Yes, Windows theme needs more work so chrome team could not enable dark mode soon.
Thanks for review!

@simonhong simonhong merged commit 02bc956 into master Mar 13, 2019
@simonhong simonhong deleted the brave_theme_service branch March 13, 2019 21:58
petemill pushed a commit that referenced this pull request Mar 13, 2019
OS(MacOS/Windows) theme controls brave theme
petemill pushed a commit that referenced this pull request Mar 13, 2019
OS(MacOS/Windows) theme controls brave theme
@bluz71
Copy link

bluz71 commented Mar 13, 2019

All issues about dark theme on MacOS are resolved.

Just a query, these fixes will be in a coming Brave release, it is not the current stable version (Version 0.61.51 Chromium: 73.0.3683.75) now, correct?

At the moment I have a mix, Light browser chrome but Dark menus (when I select Light theme). That disconnect is jarring and unpleasant. I would prefer, when Light is selected, is for all elements (at the browser level) to be light (e.g Bookmarks bar, Setting menu etc).

If a pure Light fix is coming, that is reassuring.

Best regards.

@simonhong
Copy link
Member Author

simonhong commented Mar 13, 2019

@bluz71 This PR fixed all your concerns :)
Uplift request to 0.62.x(beta) and 0.63.x(dev) for this PR are issued.
So, I assume that this fixes will be included in 0.62.x.

@bluz71
Copy link

bluz71 commented Mar 14, 2019

@simonhong,

Thank you for the confirmation, I assumed as much, but just wanted to make sure that the current release I am now using is non-optimal (confirmed as such).

Looking forward to the upcoming release.

Much appreciation to all the Brave team.

simonhong added a commit that referenced this pull request Mar 15, 2019
Uplift #1805 to 0.63 - OS appearance mode controls Brave appearance mode (light / dark theme)
simonhong added a commit that referenced this pull request Mar 15, 2019
OS(MacOS/Windows) theme controls brave theme
simonhong added a commit that referenced this pull request Mar 15, 2019
Uplift #1805 to 0.62 - OS appearance mode controls Brave appearance mode (light / dark theme)
@bsclifton
Copy link
Member

@simonhong @petemill does this (on macOS) require Mojave?

@petemill
Copy link
Member

@bsclifton yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment