---
# System prepended metadata

title: LayoutManager
tags: [Chromium-Graphics, elkurin-daily-note]

---

# LayoutManager

[LayoutManager](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/layout/layout_manager.h;l=34;drc=5ca8523b8c9ff9a7b3e7eb349d8fc7566f660675) is a base view class to provide a preferredd size infromation and to position the child views.  
Let's see their roles and how it layouts.

## Overview
LayoutManager is attached to each view.  
ui::View instance owns one [`layout_manager_`](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.h;l=2251;drc=5ca8523b8c9ff9a7b3e7eb349d8fc7566f660675) as a unique ptr.  

On [View::Layout](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=858;drc=5ca8523b8c9ff9a7b3e7eb349d8fc7566f660675), Layout method of the registered `layout_manager_` is called.  
It will recursively layout the children views.

## Methods
### Layout
[Layout](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/layout/layout_manager.h;l=50;drc=130ae0a59925a57204111bf344c5396c028e29ac) positions and sizes the children of `host`.  
[NonClientFrameView](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/window/non_client_view.cc;l=122;drc=5ca8523b8c9ff9a7b3e7eb349d8fc7566f660675) calles Layout with passing `this` as a `host`. NonClientFrameView acts as a host window here.

### Get size
[GetPreferredSize](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/layout/layout_manager.h;l=55;drc=130ae0a59925a57204111bf344c5396c028e29ac) returns a preferred size for the view.  
[GetMinimumSize](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/layout/layout_manager.h;l=60;drc=130ae0a59925a57204111bf344c5396c028e29ac) returns a minimum size for the view.  
There two methods concepts are similar. By default, GetMinimumSize returns GetPreferredSize.  
What are preferred/minimum size in this context?

For example, the top header in Chrome contains a profile icon, extension icons, back/forward button, reload button, URL bar etc...  
These features must fit in the top header.  
Therefore, the minimum width of the top header would be the sum of the width of the required elements.  
Also, URL bar being too small would make it impossible to go to the link, so it must be wide enough. It also has a minimum size.

### Children
[ViewAdded](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/layout/layout_manager.h;l=80;drc=130ae0a59925a57204111bf344c5396c028e29ac) and [ViewRemoved](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/layout/layout_manager.h;l=85;drc=130ae0a59925a57204111bf344c5396c028e29ac) controls the view hierarchy in LayoutManager.  


## Overrides
LayoutManager has many virtual methods and they are implemented by many classes such as:
- [OpaqueBrowserFrameViewLayout](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h;l=28;drc=919b38de9d8bd0a174ae53c62960868b284f168e)
- [BrowserViewLayout](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/views/frame/browser_view_layout.h;l=41;drc=6ebffd3b3ad57c09398f3ed0fc3e42a03c15b141)
- [ContentsLayoutManager](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/views/frame/contents_layout_manager.h;l=13;drc=4a8573cb240df29b0e4d9820303538fb28e31d84)
- [HUDTabStripLayout](https://source.chromium.org/chromium/chromium/src/+/main:ash/hud_display/tab_strip.cc;l=29;drc=5ca8523b8c9ff9a7b3e7eb349d8fc7566f660675)
- [EnterpriseBadgeLayout](https://source.chromium.org/chromium/chromium/src/+/main:ash/login/ui/login_user_view.cc;l=113;drc=5ca8523b8c9ff9a7b3e7eb349d8fc7566f660675)

There are many specifis layouts, but below two are the LayoutManager implementations commonly used by the browser.

[OpaqueBrowserFrameViewLayout](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h;l=28;drc=919b38de9d8bd0a174ae53c62960868b284f168e) is not built on is_chromeos platforms. Used by other platforms such as Linux.  
[BrowserViewLayout](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/views/frame/browser_view_layout.h;l=41;drc=6ebffd3b3ad57c09398f3ed0fc3e42a03c15b141) is used for chrome browser. ChromeOS platform uses this.

## Bounds of host and children
As for X11 Linux, shadow bounds is included in the non client view.  
The actual content bounds can be obtained from [CalculateClientAreBounds](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.cc;l=220;drc=5ca8523b8c9ff9a7b3e7eb349d8fc7566f660675).  This does not include shadow bounds.  
Therefore, NonClinetView's bounds() and the content bounds are different on X11.

On the other hand, on Wayland, NonClientView does not include the shadow bounds. However, the content area does not include the top header (tabstrip).
Because of the top header, bounds are still different but a different reason from X11.