Skip to content

Commit

Permalink
ash: Simplify code for PIP rounded corners
Browse files Browse the repository at this point in the history
Bug: 1217288
Test: manual
Change-Id: Ic92ea44815bb3ce0d08e61f120cfb726aba3d6ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2964245
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: Dana Fried <dfried@chromium.org>
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#892769}
  • Loading branch information
Avery Musbach authored and Chromium LUCI CQ committed Jun 15, 2021
1 parent d06ee5f commit 7a7fbd3
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 201 deletions.
5 changes: 2 additions & 3 deletions ash/public/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ component("cpp") {
"quick_answers/controller/quick_answers_controller.h",
"quick_answers/quick_answers_state.cc",
"quick_answers/quick_answers_state.h",
"rounded_corner_decorator.cc",
"rounded_corner_decorator.h",
"rounded_corner_utils.cc",
"rounded_corner_utils.h",
"rounded_image_view.cc",
"rounded_image_view.h",
"scale_utility.cc",
Expand Down Expand Up @@ -387,7 +387,6 @@ source_set("unit_tests") {
"metrics_util_unittest.cc",
"pagination/pagination_model_unittest.cc",
"power_utils_unittest.cc",
"rounded_corner_decorator_unittest.cc",
"shelf_model_unittest.cc",
"view_shadow_unittest.cc",
]
Expand Down
2 changes: 2 additions & 0 deletions ash/public/cpp/ash_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ constexpr FloatingMenuPosition kDefaultAutoclickMenuPosition =
constexpr FloatingMenuPosition kDefaultFloatingMenuPosition =
FloatingMenuPosition::kSystemDefault;

constexpr int kPipRoundedCornerRadius = 8;

} // namespace ash

#endif // ASH_PUBLIC_CPP_ASH_CONSTANTS_H_
59 changes: 0 additions & 59 deletions ash/public/cpp/rounded_corner_decorator.cc

This file was deleted.

51 changes: 0 additions & 51 deletions ash/public/cpp/rounded_corner_decorator.h

This file was deleted.

63 changes: 0 additions & 63 deletions ash/public/cpp/rounded_corner_decorator_unittest.cc

This file was deleted.

26 changes: 26 additions & 0 deletions ash/public/cpp/rounded_corner_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/public/cpp/rounded_corner_utils.h"

#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor_extra/shadow.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/wm/core/shadow_controller.h"

namespace ash {

void SetCornerRadius(aura::Window* shadow_window,
ui::Layer* layer,
int radius) {
layer->SetRoundedCornerRadius({radius, radius, radius, radius});
layer->SetIsFastRoundedCorner(true);

ui::Shadow* shadow = wm::ShadowController::GetShadowForWindow(shadow_window);
if (shadow)
shadow->SetRoundedCornerRadius(radius);
}

} // namespace ash
28 changes: 28 additions & 0 deletions ash/public/cpp/rounded_corner_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_PUBLIC_CPP_ROUNDED_CORNER_UTILS_H_
#define ASH_PUBLIC_CPP_ROUNDED_CORNER_UTILS_H_

#include "ash/public/cpp/ash_public_export.h"

namespace aura {
class Window;
}

namespace ui {
class Layer;
}

namespace ash {

// Puts rounded corners with |radius| on |layer|, and on |shadow_window|'s
// shadow if it has one. Enables fast rounded corners on |layer|.
ASH_PUBLIC_EXPORT void SetCornerRadius(aura::Window* shadow_window,
ui::Layer* layer,
int radius);

} // namespace ash

#endif // ASH_PUBLIC_CPP_ROUNDED_CORNER_UTILS_H_
7 changes: 4 additions & 3 deletions chrome/browser/ui/views/overlay/overlay_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
#include "ui/views/window/non_client_view.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/rounded_corner_utils.h"
#include "ash/public/cpp/window_properties.h" // nogncheck
#include "ui/aura/window.h"
#endif
Expand Down Expand Up @@ -853,9 +855,8 @@ void OverlayWindowViews::ShowInactive() {
#if BUILDFLAG(IS_CHROMEOS_ASH)
// For rounded corners.
if (ash::features::IsPipRoundedCornersEnabled()) {
decorator_ = std::make_unique<ash::RoundedCornerDecorator>(
GetNativeWindow(), GetNativeWindow(), GetRootView()->layer(),
ash::kPipRoundedCornerRadius);
ash::SetCornerRadius(GetNativeWindow(), GetRootView()->layer(),
ash::kPipRoundedCornerRadius);
}
#endif

Expand Down
8 changes: 0 additions & 8 deletions chrome/browser/ui/views/overlay/overlay_window_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
#include "content/public/browser/overlay_window.h"

#include "base/timer/timer.h"
#include "build/chromeos_buildflags.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/widget/widget.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/public/cpp/rounded_corner_decorator.h"
#endif

namespace views {
class BackToTabImageButton;
class CloseImageButton;
Expand Down Expand Up @@ -241,9 +236,6 @@ class OverlayWindowViews : public content::OverlayWindow,
ToggleMicrophoneButton* toggle_microphone_button_ = nullptr;
ToggleCameraButton* toggle_camera_button_ = nullptr;
HangUpButton* hang_up_button_ = nullptr;
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::unique_ptr<ash::RoundedCornerDecorator> decorator_;
#endif

// Automatically hides the controls a few seconds after user tap gesture.
base::RetainingOneShotTimer hide_controls_timer_;
Expand Down
23 changes: 12 additions & 11 deletions components/exo/client_controlled_shell_surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include "ash/frame/non_client_frame_view_ash.h"
#include "ash/frame/wide_frame_view.h"
#include "ash/public/cpp/arc_resize_lock_type.h"
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/rounded_corner_decorator.h"
#include "ash/public/cpp/rounded_corner_utils.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/window_backdrop.h"
#include "ash/public/cpp/window_properties.h"
Expand Down Expand Up @@ -53,7 +54,9 @@
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/class_property.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_lock.h"
#include "ui/compositor/layer.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/tablet_state.h"
Expand Down Expand Up @@ -1182,16 +1185,14 @@ bool ClientControlledShellSurface::OnPreWidgetCommit() {
break;
}

if (pending_window_state_ == chromeos::WindowStateType::kPip) {
if (ash::features::IsPipRoundedCornersEnabled()) {
// The host window's transform scales by |1/scale_| but we do not want the
// rounded corners scaled that way. So we multiply the radius by |scale_|.
decorator_ = std::make_unique<ash::RoundedCornerDecorator>(
window_state->window(), host_window(), host_window()->layer(),
base::ClampRound(scale_ * ash::kPipRoundedCornerRadius));
}
} else {
decorator_.reset(); // Remove rounded corners.
if (ash::features::IsPipRoundedCornersEnabled()) {
// The host window's transform scales by |1/scale_| but we do not want the
// rounded corners scaled that way. So we multiply the radius by |scale_|.
ash::SetCornerRadius(
window_state->window(), host_window()->layer(),
pending_window_state_ == chromeos::WindowStateType::kPip
? base::ClampRound(scale_ * ash::kPipRoundedCornerRadius)
: 0);
}

bool wasPip = window_state->IsPip();
Expand Down
3 changes: 0 additions & 3 deletions components/exo/client_controlled_shell_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace ash {
class NonClientFrameViewAsh;
class RoundedCornerDecorator;
class WideFrameView;

namespace mojom {
Expand Down Expand Up @@ -336,8 +335,6 @@ class ClientControlledShellSurface : public ShellSurfaceBase,

std::unique_ptr<ash::WideFrameView> wide_frame_;

std::unique_ptr<ash::RoundedCornerDecorator> decorator_;

std::unique_ptr<ui::CompositorLock> orientation_compositor_lock_;

// The orientation to be applied when widget is being created. Only set when
Expand Down

0 comments on commit 7a7fbd3

Please sign in to comment.