frame: Make FrameAnimatorView not change overall opacity

FrameAnimatorView is used when animating dark/light mode theme
switches. As part of this, it uses two layers - one with the old theme
setting, and one with the new. It then fades between these by changing
the opacity.

However, if the existing layer has had its opacity changed, then this
transition animation will effectively override the old opacity setting.
This change makes it so that the opacity of the new layer ends up
matching whatever the old layer had.

BUG=b:281152594

Change-Id: Ia1bd9a8f5013f2d6ac569dcd050754f1b9048364
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4508701
Commit-Queue: Daniel Andersson <dandersson@chromium.org>
Reviewed-by: Yongshun Liu <yongshun@chromium.org>
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1142303}
diff --git a/chromeos/ui/frame/frame_header.cc b/chromeos/ui/frame/frame_header.cc
index d00917e..02aff48 100644
--- a/chromeos/ui/frame/frame_header.cc
+++ b/chromeos/ui/frame/frame_header.cc
@@ -115,9 +115,10 @@
 
   AddLayerToRegion(old_layer, views::LayerRegion::kBelow);
 
-  // The old layer is on top and should fade out.
-  old_layer->SetOpacity(1.f);
-  new_layer->SetOpacity(1.f);
+  // The old layer is on top and should fade out. The new layer is given the
+  // opacity as the old layer is currently targeting. This ensures that we don't
+  // change the overall opacity, since it may have been set by something else.
+  new_layer->SetOpacity(old_layer->GetTargetOpacity());
   {
     ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator());
     settings.SetPreemptionStrategy(