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

WebUI: Settings & 4 different ways to override #1909

Merged
merged 15 commits into from
Apr 15, 2019
Merged

Conversation

petemill
Copy link
Member

@petemill petemill commented Mar 11, 2019

Two main areas to this PR: The Settings page, and architectural changes to the way we modify chromium WebUIs.

WebUI Settings

  • A fixed page sub-navigation (on wider windows)
  • Inject a get-started section
  • Brave-styles across more material components
  • Fix some issues with Brave's added sections (e.g. Extensions) showing up during all searches

Fix brave/brave-browser#958
Fix brave/brave-browser#960
Fix brave/brave-browser#955
Address brave/brave-browser#26 (this is more of an umbrella issue)
Fix brave/brave-browser#964
Fix brave/brave-browser#3444
Fix brave/brave-browser#3826

WebUI General overriding

  1. Add a behavior to an existing Polymer JS component. This is similar to injecting a superclass which will receive the same lifecycle method calls. It could also be used to add properties and methods to the component, usable from the component's html template.

  2. Modify an existing Polymer HTML template. When the component is registered, we provide the template DOM element which can be modified before it is cloned for use as content and attached to the document.

  3. Inject style to any existing Polymer HTML component. By naming a module 'brave-override-style-my-module', the <style> element from that module will be taken and injected in to the existing 'my-module' component.

  4. Replace icons in an existing iconset. This takes an icon from one existing iconset and replaces the content of an icon in another existing iconset. Can be used to replace a chromium icon with a brave icon.

Whilst all this can be achieved via .patch files at sync / build time, this new methodology:

  • Keeps all the modifications functional. The advantage here is realized in the 100% inevitable and likely-common scenarios where the chromium webui implementations and underlying technology changes (e.g. html-modules vs es-modules, or simple module refactors). For some scenarios, we may be able to simply modify the central manipulation library (polymer_overrides.js). In more complicated scenarios, we will at least have all modifications functionally and individually labelled, making 'rebasing' potentially more straightforward than a .patch file with mixed intentions.
  • Maintains performance since these modifications are only performed once, whilst the component is being registered via the Polymer(component) function.

Debugging:

  • Display (in verbose console log) how long it took to modify each Polymer template
  • Option to see timing of module and module-override registration (via hard-coded debug variable)

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:

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

@petemill petemill self-assigned this Mar 11, 2019
@petemill petemill force-pushed the webui-settings-brave branch 2 times, most recently from 36a3c1e to 964608f Compare March 15, 2019 21:01
@petemill
Copy link
Member Author

I'm done with functionality for this PR. Just dealing with a slightly complicated rebase now.

@petemill petemill force-pushed the webui-settings-brave branch 3 times, most recently from 3a15388 to 74f5c1d Compare March 19, 2019 03:34
@petemill petemill marked this pull request as ready for review March 19, 2019 04:13
@petemill
Copy link
Member Author

petemill commented Mar 19, 2019

Some pure refactoring follow-ups I'd like to do for WebUIs after this:

  • Move some of the other patching to this style of functional modification
  • Split up settings_overrides.js in to functional files instead of a single large file.
  • Consider using webpack to generate certain JS files (such as settings_overrides.js)

@bsclifton
Copy link
Member

bsclifton commented Mar 19, 2019

I rebased this so I can build- after a completely fresh Release build (deleted src/out, no sccache), I see the following (notice the weird border on the right of the sidebar nav):
Screen Shot 2019-03-19 at 12 43 01 PM

@bsclifton
Copy link
Member

I think the padding/margin under About Brave is a bit excessive. From the original mock-up:
Screen Shot 2019-03-19 at 12 47 57 PM

@bsclifton
Copy link
Member

bsclifton commented Mar 19, 2019

I remember there were some difficulties- but wanted to check.

Shouldn't there be icons next to each of the titles?

mock-up (shown in brave/brave-browser#955 and brave/brave-browser#964):
Screen Shot 2019-03-19 at 12 48 49 PM

implementation:
Screen Shot 2019-03-19 at 12 45 57 PM

@bsclifton
Copy link
Member

@srirambv already captured with brave/brave-browser#3633 - but the focus ring (aria?) looks odd. Not sure if border radius can be added? We don't have to solve this now of course
Screen Shot 2019-03-19 at 1 06 03 PM

@bsclifton
Copy link
Member

This new section needs an entry on the sidebar nav (and icon):
Screen Shot 2019-03-19 at 1 13 05 PM

@bsclifton
Copy link
Member

Not sure if it's because I'm on a fresh profile? but trying to visit any of the autofill options leaves me at a blank page
Screen Shot 2019-03-19 at 1 18 20 PM

Clicking goes to:
Screen Shot 2019-03-19 at 1 19 10 PM

Expected to see something like:
Screen Shot 2019-03-19 at 1 19 35 PM

@bsclifton bsclifton added this to the 0.64.x - Nightly milestone Mar 19, 2019
@bsclifton
Copy link
Member

@petemill I updated all the issues closed and added the appropriate milestone/labels/test plans 😄 Please just double check those

Functionally - I called out everything I found when reviewing above 😄 Great job on this!

Going to continue reviewing / looking at the code

// then section is no longer 'selected'.
// TODO(petemill): If this wasn't a chromium module, we'd simply add a handler
// for scrolling away, or have the menu change selection as we scroll.
stopObservingScroll()
Copy link
Member

Choose a reason for hiding this comment

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

curious about this code... let's say I click Get Started. Sidebar properly shows it selected (orange). As I scroll down, it does "go out of scope" and un-select itself. But I'm not seeing Extensions, Sync, Appearance, etc select themselves. Is the highlighted section supposed to be shown? (also, if so- maybe we can call out in test plan)

Copy link
Member Author

Choose a reason for hiding this comment

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

@bsclifton no support for scrolling as you move. Just kept the current chromium highlighting behavior and removed it when scrolling away so it's not confusing. As the comment says, if we want to add more custom code then we can add a feature to have the menu change selection as we scroll, but I'm not sure I'd be in favor of that as it gets complicated when there are multiple items on the screen, or the scroll never gets that far.

For now, the selection on clicking an item is a nice feedback to the menu interaction.

// TODO(petemill): If this wasn't a chromium module, we'd simply add a handler
// for scrolling away, or have the menu change selection as we scroll.


// Templates
BravePatching.RegisterPolymerTemplateModifications({
'settings-ui': (templateContent) => {
Copy link
Member

Choose a reason for hiding this comment

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

for other reviewers: the keys here (ex: settings-ui) are the names of components on the page 😄

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Feedback left! Awesome job on this. Would love to re-review when it's ready, just hit me up 😄

@petemill
Copy link
Member Author

@srirambv already captured with brave/brave-browser#3633 - but the focus ring (aria?) looks odd. Not sure if border radius can be added? We don't have to solve this now of course
Screen Shot 2019-03-19 at 1 06 03 PM

Button style was changed before this PR, so can be addressed separately.

I remember there were some difficulties- but wanted to check.

Shouldn't there be icons next to each of the titles?

mock-up (shown in brave/brave-browser#955 and brave/brave-browser#964):
Screen Shot 2019-03-19 at 12 48 49 PM

implementation:
Screen Shot 2019-03-19 at 12 45 57 PM

The implementation of this will be more involved, which warrants reprioritization and not delaying this one IMO. The complication is that it will require template modification for the settings-section component as well as a new property added to the JS side of the component which can determine which icon to show.

As with other things, I decided to draw the line somewhere considering the size of this PR and the need to improve the current state of the page, so there were some things that were more minor and will be follow-ups:

I'll look at the other issues @bsclifton brought up - I wasn't experiencing some of them after yesterday's rebase, so maybe they're introduced by today's rebase.

@rossmoody
Copy link
Contributor

I remember there were some difficulties- but wanted to check.

Shouldn't there be icons next to each of the titles?

mock-up (shown in brave/brave-browser#955 and brave/brave-browser#964):
Screen Shot 2019-03-19 at 12 48 49 PM

implementation:
Screen Shot 2019-03-19 at 12 45 57 PM

The design mockup did have those icons in the titles but after giving it some thought, I think we should hold off on them. It's not a great UI pattern (in particular for a settings page vs a marketing page) and makes scanning the content quickly quite a bit more difficult.

@petemill
Copy link
Member Author

@rossmoody that decision seems timely! Please add the comment to brave/brave-browser#3797 if not already

@petemill
Copy link
Member Author

@bsclifton shields description padding has been increased, and @rossmoody 's style updates integrated. Watching PR builder and attempting to fix issues...

petemill and others added 15 commits April 13, 2019 13:47
1. Add a behavior to an existing Polymer JS component. This is similar to injecting a superclass which will receive the same lifecycle method calls. It could also be used to add properties and methods to the component, usable from the component's html template.

2. Modify an existing Polymer HTML template. When the component is registered, we provide the template DOM element which can be modified before it is cloned for use as content and attached to the document.

3. Inject style to any existing Polymer HTML component. By naming a module 'brave-override-style-my-module', the <style> element from that module will be taken and injected in to the existing 'my-module' component.

4. Replace icons in an existing iconset. This takes an icon from one existing iconset and replaces the content of an icon in another existing iconset. Can be used to replace a chromium icon with a brave icon.

Whilst all this can be achieved via .patch files at sync / build time, this:
- Keeps all the modifications functional. The advantage here is realized in the 100% inevitable and likely-common scenarios where the chromium webui implementations and underlying technology changes (e.g. html-modules vs es-modules, or simple module refactors). For some scenarios, we may be able to simply modify the central manipulation library (polymer_overrides.js). In more complicated scenarios, we will at least have all modifications functionally and individually labelled, making 'rebasing' potentially more straightforward than a .patch file with mixed intentions.
- Maintains performance since these modifications are only performed once, whilst the component is being registered via the Polymer(component) function.

Debugging:
- Display (in verbose console log) how long it took to modify each Polymer template
- Option to see timing of module and module-override registration (via hard-coded debug variable)
…n, re-organize other sections, and brave-styles

Ensures each section shows and hides appropriately

Fixes brave's custom sections showing up for all searches since they need a settings-section to be inside the settings/basic-page module.
Also fixes some extra and missing borders between settings items.
…tings, Bookmarks, Downloads, History and Extensions

Note that chrome://brave-resources/page_specific/X url-data-source is used for convenience. Technically these belong in //browser/resources and not //ui/resources, and served from, for example, chrome://bookmarks/X instead. However, the build setup neccessary to copy in to the chromium build output directory before the PAK and Vulcanize process is a lot of overhead for a couple lines of simple css. In the future we may wish to do this setup.
Co-authored by: Ross Moody <fiftyfivehis@gmail.com>
Co-authored by: Pete Miller <miller.pete@gmail.com>
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

++! 😎👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants