Peter Kasting | 198b59f | 2023-02-16 19:50:04 | [diff] [blame] | 1 | # Starter Guide |
| 2 | |
| 3 | You just got tasked with implementing some new UI surface in Chrome, the UX |
| 4 | designer gave you a few mocks, and your tech lead told you they expect it should |
| 5 | only take you a few days. Help! You've never built UI before! What do you do? |
| 6 | |
| 7 | Take a deep breath. We're here to help. Hopefully the following will get you |
| 8 | started. |
| 9 | |
| 10 | ## General Principles |
| 11 | |
| 12 | * **Ignorance is ok.** UI is a specialized field, and if you haven't worked with |
| 13 | it before, there's no reason you should know everything. Even if you have done |
| 14 | UI development on other products or on the web, the Views toolkit has some |
| 15 | differences that might leave yourself scratching your head. Don't spend too long |
| 16 | trying to figure things out yourself; |
| 17 | [ask questions](https://chromium.googlesource.com/chromium/src/+/main/docs/ui/ask/index.md) |
| 18 | early and often, before you discover in code review that that lovely solution |
| 19 | you found is actually a pattern the team is trying to eliminate. |
| 20 | |
| 21 | * **Don't cargo-cult.** Just as you may be ignorant, others may be too: |
| 22 | specifically, both the designers of your feature, and the authors of other UI in |
| 23 | Chrome. Blindly following is unsafe, so start by sending your feature to the |
| 24 | [desktop UI mailing list](http://go/cr-ui-process), even if you've been assured |
| 25 | it passes UX review. Then, while implementing, study the documented |
| 26 | [best practices](learn/index.md#best-practices), and ensure your code adheres to |
| 27 | them, even if other code you're referencing does not. |
| 28 | |
| 29 | * **Support all users.** Chrome ships on |
| 30 | [multiple platforms](views/platform_style.md), so try to build and test on |
| 31 | multiple platforms yourself. Users have different themes, so make sure your |
| 32 | design works for the built-in light and dark themes |
| 33 | [as well as custom themes](create/examples/theme_aware.md). Users may have |
| 34 | different needs and abilities, so ensure your design takes |
| 35 | [accessibility](http://go/gar) sufficiently into account. |
| 36 | |
| 37 | * **Build for the long term.** Chrome has a rapid release schedule in part so we |
| 38 | don't feel pressure to ship changes before they're ready. It's easy for |
| 39 | engineers to ship UI and leave it unmaintained, adding to the deifficulty of |
| 40 | future refactors and stylistic changes. So expect reviewers to set a high bar. |
| 41 | Ask how to structure your classes in keeping with MVC (Model-View-Controller) |
| 42 | principles. Write automated tests for your feature, including both functional |
| 43 | tests and pixel tests. And make sure your subteam, or another subteam, is |
| 44 | explicitly signed up to own the code you write going forward and has a triage |
| 45 | process to categorize and address bugs in it. |
| 46 | |
| 47 | ## Necessary Background |
| 48 | |
| 49 | The Views toolkit was purpose-built to render Chrome's UI on desktop platforms. |
| 50 | It lacks many features of general-purpose UI toolkits, and adds features on |
| 51 | request, rather than speculatively. It's possible that over time, more UI will |
| 52 | be built with web technologies, as some of the original design constraints that |
| 53 | led to Views' creation become less applicable, and since it is difficult to |
| 54 | justify the engineering investment necessary to implement significant modern |
| 55 | UI toolkit features (e.g. declarative UI or stylesheets). |
| 56 | |
| 57 | The best way to familiarize yourself with Views is to build a |
| 58 | [simple UI example](create/examples/login_dialog.md). This should give you |
| 59 | sufficient context to understand some |
| 60 | [important parts of the system](views/overview.md). Along the way, if you run |
| 61 | into jargon you don't understand, you can look for a definition in the |
| 62 | [glossary](learn/glossary.md) (or request one, if you don't see what you need). |
| 63 | |
| 64 | At this point, you should be ready to start building your UI, following the |
| 65 | steps below. |
| 66 | |
| 67 | ## Building Your UI |
| 68 | |
| 69 | 1. Make sure there is a [bug](http://crbug.com/) on file with a description of |
| 70 | the UI you're building, and a link to any relevant design docs or mocks. Assume |
| 71 | readers aren't familiar with your subteam/product area already and provide |
| 72 | enough background that, without clicking through to other documentation, a new |
| 73 | code reviewer can understand the basic idea you're trying to accomplish. |
| 74 | |
| 75 | 1. If it hasn't already happened, send mail to the |
| 76 | [desktop UI mailing list](http://go/cr-ui-process) describing the proposed UX. |
| 77 | The primary purpose is for knowledgeable folks on this list to flag designs that |
| 78 | are atypical in Chrome or will be difficult to implement; these might require |
| 79 | further tweaks from the UX designers. This can be a frustrating process if you |
| 80 | assume UX mocks are set in stone, but the goal is not to derail your feature; |
| 81 | it's to ensure everyone is aware of what tradeoffs must be made to implement the |
| 82 | feature in a way that supports all users and is maintainable for the indefinite |
| 83 | future. |
| 84 | |
| 85 | 1. Ensure your UX mocks are semantic, not physical. That is, they should explain |
| 86 | what a feature does and how it relates to other similar UI (e.g. "use standard |
| 87 | dialog borders" or "match accent color used for radio buttons elsewhere"), |
| 88 | ideally by referencing standardized color or layout names/tokens; they should |
| 89 | not simply give you hardcoded values ("16 dp", "Google Grey 300"). Hardcoded |
| 90 | values cannot be systematized in a way that accommodates users with different |
| 91 | font sizes or themes, or changes over time in Chrome's systematic design |
| 92 | aesthetic. Semantics tell you how to obtain the desired values from classes in |
| 93 | Chrome that are designed to provide the appropriate physical values for your |
| 94 | context. |
| 95 | |
| 96 | 1. Look for similar UI implementations in Chrome and study how they function, |
| 97 | but don't blindly copy them. The majority of Chrome UI is years old and was |
| 98 | written before current best practices were established and documented, so while |
| 99 | existing code can be a good source of inspiration, it usually needs modification |
| 100 | before it's fit for reuse. |
| 101 | |
| 102 | 1. Add a [feature flag](/docs/how_to_add_your_feature_flag.md) to gate your UI, |
| 103 | and implement it locally. Some engineers prefer to send CLs as they implement |
| 104 | each small piece, while others prefer to get something mostly complete done |
| 105 | locally before polishing things for review; either way, ensure the changes you |
| 106 | send for review are small enough to be manageable but still provide sufficient |
| 107 | context for your reviewer to understand what's happening. |
| 108 | |
| 109 | 1. When preparing a CL for code review, run through |
| 110 | [this checklist](learn/bestpractices/prepare_for_code_review.md). |
| 111 | |
| 112 | 1. Before considering your feature complete, ensure it has automated testing. In |
| 113 | most cases, this can be accomplished using |
| 114 | [`TestBrowserUi`](/docs/testing/test_browser_dialog.md) or an appropriate |
| 115 | subclass; if the feature is built using MVC design principles, you can hopefully |
| 116 | also unit-test the business logic separately. If possible, opt in to pixel tests |
| 117 | using [Skia Gold](learn/glossary.md#skia-gold). |
| 118 | |
| 119 | ## Further Resources |
| 120 | |
| 121 | * If you're a Noogler on the Chrome team, welcome! You should have gotten this |
| 122 | already, but |
| 123 | [here](https://sites.google.com/corp/google.com/chrome-top-level/more-resources/new-to-chrome) |
| 124 | are some hopefully-helpful docs as you ramp up on Chrome in general; |
| 125 | [here](/docs/contributing.md) are docs on the general contribution process. |
| 126 | * Is it possible to debug the UI that you're building? Yes! |
| 127 | [Here](learn/ui_debugging.md) are a few tools to help you. |