Consider shorthands when removing equivalent properties from styles

As part of some editing operations, like removing line-breaks, a DOM
node may get merged into a different inline-block, hence inserted in a
different parent. This operation normally wants the node's original
inline style to be preserved, but we want to avoid redundant properties
based on the inheritance from its new parent.

The RemoveRedundantStylesAndKeepStyleSpanInline method implemented in
the ReplaceSelectionCommand class takes care of the logic to analyze how
the new inheritance affects to the node's style. For inline styles, it
basically uses the RemoveStyleFromRulesAndContext method from the
EditingStyle class.

The root cause of the bug comes from the GetPropertiesNotIn() method and
how it chooses the properties to remove from the CSSPropertyValueSet
instance. The current implementation just iterates along the registered
longhand properties, comparing their values with the respective
properties in the new node's parent. However, this logic doesn't
consider whether the properties' value come from a shorthand declaration
in the original style.

The bug is only reproducible when inspecting the serialized DOM after
executing the editing operation, as it's done in the WPT editing tests,
which fail only in chrome, described in the bug report.

We only have hit by the bug when we implemented the "white-space"
property as a shorthand, as part of the CSS Text L4 spec, which is
correct, but we need to consider it when reconstructing the DOM tree
after certain editing operations.

The proposed solution is to define a new method in the
CSSPropertyValueSet to remove the equivalent properties; in the case of
the ones getting their value from a shorthand, they are only removed if
all its associated longhands are equivalent. This function will be only
used, for now, in the inline-style reconstruction logic performed as
part of the ReplaceSelectionCommand operations. We may want to apply it
to other editing-related operations in the future, and perhaps it'd make
sense to integrate it in the common RemoveEquivalentProperties method of
the CSSPropertyValueSet class.

Bug: 483903178
Change-Id: I0b72dc6a32c8e5be5fceb5df5a802e85e9fe4a46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7511015
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Reviewed-by: Dan Clark <daniec@microsoft.com>
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1592297}
46 files changed
tree: fc133a42da9d8f058efb5612b5b9e4ac693dc76b
  1. .agents/
  2. .claude/
  3. .gemini/
  4. .github/
  5. agents/
  6. android_webview/
  7. apps/
  8. ash/
  9. base/
  10. build/
  11. build_overrides/
  12. buildtools/
  13. cc/
  14. chrome/
  15. chromecast/
  16. chromeos/
  17. codelabs/
  18. components/
  19. content/
  20. crypto/
  21. dbus/
  22. device/
  23. docs/
  24. extensions/
  25. fuchsia_web/
  26. gin/
  27. google_apis/
  28. gpu/
  29. headless/
  30. infra/
  31. ios/
  32. ipc/
  33. media/
  34. mojo/
  35. net/
  36. pdf/
  37. printing/
  38. remoting/
  39. rlz/
  40. sandbox/
  41. services/
  42. skia/
  43. sql/
  44. storage/
  45. styleguide/
  46. testing/
  47. third_party/
  48. tools/
  49. ui/
  50. url/
  51. webkit/
  52. .clang-format
  53. .clang-tidy
  54. .clangd
  55. .cursorignore
  56. .geminiignore
  57. .git-blame-ignore-revs
  58. .gitallowed
  59. .gitattributes
  60. .gitignore
  61. .gitmodules
  62. .gn
  63. .mailmap
  64. .rustfmt.toml
  65. .vpython3
  66. .yapfignore
  67. ATL_OWNERS
  68. AUTHORS
  69. BUILD.gn
  70. CODE_OF_CONDUCT.md
  71. codereview.settings
  72. CPPLINT.cfg
  73. CRYPTO_OWNERS
  74. DEPS
  75. DIR_METADATA
  76. LICENSE
  77. LICENSE.chromium_os
  78. OWNERS
  79. package.json
  80. PRESUBMIT.py
  81. PRESUBMIT_test.py
  82. PRESUBMIT_test_mocks.py
  83. README.md
  84. SECURITY_OWNERS
  85. WATCHLISTS
README.md

Logo Chromium

Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web.

The project's web site is https://www.chromium.org.

To check out the source code locally, don't use git clone! Instead, follow the instructions on how to get the code.

Documentation in the source is rooted in docs/README.md.

Learn how to Get Around the Chromium Source Code Directory Structure.

For historical reasons, there are some small top level directories. Now the guidance is that new top level directories are for product (e.g. Chrome, Android WebView, Ash). Even if these products have multiple executables, the code should be in subdirectories of the product.

If you found a bug, please file it at https://crbug.com/new.