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