Files
brave-core/android/java
AlexeyBarabash 282b13ecb9 [cr144][Android] Fix for NTP shortcuts when NTP images are turned off
STR to verify there is no crash:
1. Pin one shortcut
2. Turn background images off
3. Restart

Chromium change:
https://source.chromium.org/chromium/chromium/src/+/a11ac5d97f40076f5d1502084c6ef8972cff2a22

[MVT] Fix MVT container sizing and centering on Tablets.

By "blocks" we include MVT tiles and the "Add now" button.

On Tablets, blocks and its container have special behavior:
1. Depending on **initial** block count, these render in modes:
  * Centered: With "few" blocks present: The container is WRAP_CONTENT,
    and "edge margins" (outer margin of outer blocks) expanded so blocks
    are centered and immobile.
  * Overflowed: With "many" blocks present: The container is
    MATCH_PARENT, and "edge margins" are assigned a fixed value. The
    blocks become scrollable.
2. When changing from "many" blocks to "few" blocks, the Overflowed
   state remains. In this case, blocks no longer scroll, and are start-
   aligned instead of centered.

(2) was intentional, presumably to reduce tiles "jumping" on repeated
tile removal. NewTabPageLayout (for container) and TilesLinearLayout
(for "edge margins") implemented this by doing the following:
* Store initial tile count and block count.
* Use these counts and width constants to compute "content width".
* If "content width" <= "container" size then Centered (AKA "full
  filled", "all filled"); else Overflowed.

Now, MVT on tablets has some longstanding oddities
O1. When Centered, the container might not reach full width.
O2. Container may shrink on repeated tile removal (and centered) --
    this is a cross between Centered (re. WRAP_CONTENT) and Overflowed
    (re. fixed "edge margin") modes.
O3. When changing from "few" blocks to "many" blocks (by adding Custom
    Tiles), Overflow mode does kick in sometimes, leading to blocks
    appearing off-screen but cannot be scrolled to.

This CL fixes the oddities and removes behavior (2); now Centered and
Overflowed behavior depends on **current** (instead of the initial)
block count -- this fixes (O3). High level changes:
* Stop storing initial tile and block counts.
* Centralize Centered / Overflowed decision, including "content width"
  computation, to MostVisitedTilesLayout.
* Change MVT child addition semantics from {Tile, non-Tile} to
  {Tile, Divider, UI View (for the "Add new" button)}.

Bugs that were found and fixed:
* The duplicated Centered / Overflowed decision logic were inconsistent;
  the NewTabPageLayout version (for WRAP_CONTENT / MATCH_PARENT) didn't
  account for Custom Tile changes, i.e., divider & "Add new" button.
  This led to (O2), and is fixed when we dedup the logic.
* When "divider gap" was changed to same as "tile gap" in
  crrev.com/c/6780677 , we didn't update "content width" calculation.
  This also led to (O2), and is fixed by having dividers not contribute
  to "content width".
* Resources.getDimension() returns (float) PX value, and NOT DP. The
  misunderstanding led to explicit conversions that made the width of
  the "Add new" too large (TileRenderer.renderTileSection()). This led
  to (O1). Fixing this also simplified code.

Bug: 447086773, 388782412
Change-Id: Id1400e672f1f0be11b4cc218cd20521988c3455f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7004884
2025-12-21 17:13:21 -05:00
..