chromium/chrome/browser/ui/views/frame/picture_in_picture_browser_frame_view.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/frame/picture_in_picture_browser_frame_view.h"

#include "base/metrics/histogram_functions.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_occlusion_tracker.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model_states.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/frame/browser_frame_bounds_change_animation.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/top_container_view.h"
#include "chrome/browser/ui/views/overlay/overlay_window_image_button.h"
#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/ui/frame/frame_utils.h"
#include "components/omnibox/browser/location_bar_model_impl.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/document_picture_in_picture_window_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_constants.h"
#include "extensions/buildflags/buildflags.h"
#include "media/base/media_switches.h"
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/base/ui_base_features.h"
#include "ui/compositor/layer.h"
#include "ui/display/screen.h"
#include "ui/events/event_observer.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/animation/animation_container.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/compositor_animation_runner.h"
#include "ui/views/event_monitor.h"
#include "ui/views/layout/animating_layout_manager.h"
#include "ui/views/layout/flex_layout_view.h"
#include "ui/views/style/typography.h"
#include "ui/views/style/typography_provider.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/window/frame_background.h"
#include "ui/views/window/window_shape.h"

#if BUILDFLAG(IS_WIN)
#include "ui/base/win/hwnd_metrics.h"
#include "ui/views/win/hwnd_util.h"
#endif

#if !BUILDFLAG(IS_MAC)
// Mac does not use Aura
#include "ui/aura/window.h"
#endif

#if BUILDFLAG(IS_LINUX)
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/views/frame/browser_frame_view_paint_utils_linux.h"
#include "chrome/browser/ui/views/frame/desktop_browser_frame_aura_linux.h"
#include "ui/linux/linux_ui.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/ui/base/window_properties.h"
#include "chromeos/ui/base/window_state_type.h"
#include "chromeos/ui/frame/interior_resize_handler_targeter.h"
#endif

#if RESIZE_DOCUMENT_PICTURE_IN_PICTURE_TO_DIALOG
#include "ui/aura/client/transient_window_client.h"
#include "ui/aura/window.h"
#endif  // RESIZE_DOCUMENT_PICTURE_IN_PICTURE_TO_DIALOG

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/constants.h"
#endif  // BUILDFLAG(ENABLE_EXTENSIONS)

namespace {

constexpr int kWindowIconImageSize =;
constexpr int kBackToTabImageSize =;
constexpr int kContentSettingIconSize =;

// The height of the controls bar at the top of the window.
constexpr int kTopControlsHeight =;

#if BUILDFLAG(IS_LINUX)
// Frame border when window shadow is not drawn.
constexpr int kFrameBorderThickness =;
#endif

#if !BUILDFLAG(IS_CHROMEOS_ASH)
constexpr int kResizeBorder =;
#endif
constexpr int kResizeAreaCornerSize =;

// The time duration that the top bar animation will take in total.
constexpr base::TimeDelta kAnimationDuration =;

// The animation durations for the top right buttons, which are separated into
// multiple parts because some changes need to be delayed.
constexpr std::array<base::TimeDelta, 2>
    kMoveCameraButtonToRightAnimationDurations =;
constexpr std::array<base::TimeDelta, 3>
    kShowBackToTabButtonAnimationDurations =;
constexpr std::array<base::TimeDelta, 2>
    kHideBackToTabButtonAnimationDurations =;
constexpr std::array<base::TimeDelta, 3> kCloseButtonAnimationDurations =;

constexpr base::TimeDelta kShowHideAllButtonsAnimationDuration =;

class BackToTabButton : public OverlayWindowImageButton {};

BEGIN_METADATA()

// Helper class for observing mouse and key events from native window.
class WindowEventObserver : public ui::EventObserver {};

void DefinitelyExitPictureInPicture(
    PictureInPictureBrowserFrameView& frame_view,
    PictureInPictureWindowManager::UiBehavior behavior) {}

}  // namespace

#if RESIZE_DOCUMENT_PICTURE_IN_PICTURE_TO_DIALOG
PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    ChildDialogObserverHelper(views::Widget* pip_widget)
    :{}

PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    ~ChildDialogObserverHelper() = default;

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    OnWidgetBoundsChanged(views::Widget* widget, const gfx::Rect& new_bounds) {}

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    OnWidgetDestroying(views::Widget* widget) {}

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    OnWidgetVisibilityChanged(views::Widget* widget, bool visible) {}

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::OnWindowAdded(
    aura::Window* new_window) {}

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    OnTransientChildWindowAdded(aura::Window* parent,
                                aura::Window* transient_child) {}

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    OnChildDialogOpened(views::Widget* child_dialog) {}

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    MaybeResizeForChildDialog(views::Widget* child_dialog) {}

void PictureInPictureBrowserFrameView::ChildDialogObserverHelper::
    MaybeRevertSizeAfterChildDialogCloses() {}
#endif  // RESIZE_DOCUMENT_PICTURE_IN_PICTURE_TO_DIALOG

PictureInPictureBrowserFrameView::PictureInPictureBrowserFrameView(
    BrowserFrame* frame,
    BrowserView* browser_view)
    :{}

PictureInPictureBrowserFrameView::~PictureInPictureBrowserFrameView() {}

///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameView implementations:

gfx::Rect PictureInPictureBrowserFrameView::GetBoundsForTabStripRegion(
    const gfx::Size& tabstrip_minimum_size) const {}

gfx::Rect PictureInPictureBrowserFrameView::GetBoundsForWebAppFrameToolbar(
    const gfx::Size& toolbar_preferred_size) const {}

void PictureInPictureBrowserFrameView::LayoutWebAppWindowTitle(
    const gfx::Rect& available_space,
    views::Label& window_title_label) const {}

int PictureInPictureBrowserFrameView::GetTopInset(bool restored) const {}

void PictureInPictureBrowserFrameView::OnBrowserViewInitViewsComplete() {}

gfx::Rect PictureInPictureBrowserFrameView::GetBoundsForClientView() const {}

gfx::Rect PictureInPictureBrowserFrameView::GetWindowBoundsForClientBounds(
    const gfx::Rect& client_bounds) const {}

int PictureInPictureBrowserFrameView::NonClientHitTest(
    const gfx::Point& point) {}

void PictureInPictureBrowserFrameView::GetWindowMask(const gfx::Size& size,
                                                     SkPath* window_mask) {}

void PictureInPictureBrowserFrameView::UpdateWindowIcon() {}

// Minimum size refers to the minimum size for the window inner bounds.
gfx::Size PictureInPictureBrowserFrameView::GetMinimumSize() const {}

gfx::Size PictureInPictureBrowserFrameView::GetMaximumSize() const {}

void PictureInPictureBrowserFrameView::OnThemeChanged() {}

void PictureInPictureBrowserFrameView::Layout(PassKey) {}

void PictureInPictureBrowserFrameView::AddedToWidget() {}

void PictureInPictureBrowserFrameView::RemovedFromWidget() {}

#if BUILDFLAG(IS_LINUX)
gfx::Insets
PictureInPictureBrowserFrameView::RestoredMirroredFrameBorderInsets() const {}

gfx::Insets PictureInPictureBrowserFrameView::GetInputInsets() const {}

SkRRect PictureInPictureBrowserFrameView::GetRestoredClipRegion() const {}
#endif

void PictureInPictureBrowserFrameView::SetFrameBounds(const gfx::Rect& bounds) {}

///////////////////////////////////////////////////////////////////////////////
// ChromeLocationBarModelDelegate implementations:

content::WebContents* PictureInPictureBrowserFrameView::GetActiveWebContents()
    const {}

bool PictureInPictureBrowserFrameView::GetURL(GURL* url) const {}

bool PictureInPictureBrowserFrameView::ShouldPreventElision() {}

bool PictureInPictureBrowserFrameView::ShouldTrimDisplayUrlAfterHostName()
    const {}

bool PictureInPictureBrowserFrameView::ShouldDisplayURL() const {}

///////////////////////////////////////////////////////////////////////////////
// LocationIconView::Delegate implementations:

content::WebContents* PictureInPictureBrowserFrameView::GetWebContents() {}

bool PictureInPictureBrowserFrameView::IsEditingOrEmpty() const {}

SkColor PictureInPictureBrowserFrameView::GetSecurityChipColor(
    security_state::SecurityLevel security_level) const {}

bool PictureInPictureBrowserFrameView::ShowPageInfoDialog() {}

LocationBarModel* PictureInPictureBrowserFrameView::GetLocationBarModel()
    const {}

ui::ImageModel PictureInPictureBrowserFrameView::GetLocationIcon(
    LocationIconView::Delegate::IconFetchedCallback on_icon_fetched) const {}

std::optional<ui::ColorId>
PictureInPictureBrowserFrameView::GetLocationIconBackgroundColorOverride()
    const {}

///////////////////////////////////////////////////////////////////////////////
// IconLabelBubbleView::Delegate implementations:

SkColor
PictureInPictureBrowserFrameView::GetIconLabelBubbleSurroundingForegroundColor()
    const {}

SkColor PictureInPictureBrowserFrameView::GetIconLabelBubbleBackgroundColor()
    const {}

///////////////////////////////////////////////////////////////////////////////
// ContentSettingImageView::Delegate implementations:

bool PictureInPictureBrowserFrameView::ShouldHideContentSettingImage() {}

content::WebContents*
PictureInPictureBrowserFrameView::GetContentSettingWebContents() {}

ContentSettingBubbleModelDelegate*
PictureInPictureBrowserFrameView::GetContentSettingBubbleModelDelegate() {}

///////////////////////////////////////////////////////////////////////////////
// views::WidgetObserver implementations:

void PictureInPictureBrowserFrameView::OnWidgetActivationChanged(
    views::Widget* widget,
    bool active) {}

void PictureInPictureBrowserFrameView::OnWidgetDestroying(
    views::Widget* widget) {}

void PictureInPictureBrowserFrameView::OnWidgetBoundsChanged(
    views::Widget* widget,
    const gfx::Rect& new_bounds) {}

///////////////////////////////////////////////////////////////////////////////
// gfx::AnimationDelegate implementations:

void PictureInPictureBrowserFrameView::AnimationEnded(
    const gfx::Animation* animation) {}

void PictureInPictureBrowserFrameView::AnimationProgressed(
    const gfx::Animation* animation) {}

///////////////////////////////////////////////////////////////////////////////
// views::View implementations:

void PictureInPictureBrowserFrameView::OnPaint(gfx::Canvas* canvas) {}

///////////////////////////////////////////////////////////////////////////////
// PictureInPictureBrowserFrameView implementations:

gfx::Rect PictureInPictureBrowserFrameView::ConvertTopBarControlViewBounds(
    views::View* control_view,
    views::View* source_view) const {}

gfx::Rect PictureInPictureBrowserFrameView::GetLocationIconViewBounds() const {}

gfx::Rect PictureInPictureBrowserFrameView::GetContentSettingViewBounds(
    size_t index) const {}

gfx::Rect PictureInPictureBrowserFrameView::GetBackToTabControlsBounds() const {}

gfx::Rect PictureInPictureBrowserFrameView::GetCloseControlsBounds() const {}

LocationIconView* PictureInPictureBrowserFrameView::GetLocationIconView() {}

void PictureInPictureBrowserFrameView::UpdateContentSettingsIcons() {}

void PictureInPictureBrowserFrameView::UpdateTopBarView(bool render_active) {}

gfx::Insets PictureInPictureBrowserFrameView::FrameBorderInsets() const {}

gfx::Insets PictureInPictureBrowserFrameView::ResizeBorderInsets() const {}

int PictureInPictureBrowserFrameView::GetTopAreaHeight() const {}

gfx::Size PictureInPictureBrowserFrameView::GetNonClientViewAreaSize() const {}

#if BUILDFLAG(IS_LINUX)
bool PictureInPictureBrowserFrameView::ShouldDrawFrameShadow() const {}

// static
gfx::ShadowValues PictureInPictureBrowserFrameView::GetShadowValues() {}
#endif

#if BUILDFLAG(IS_WIN)
gfx::Insets PictureInPictureBrowserFrameView::GetClientAreaInsets(
    HMONITOR monitor) const {
  const int frame_thickness = ui::GetFrameThickness(monitor);
  return gfx::Insets::TLBR(0, frame_thickness, frame_thickness,
                           frame_thickness);
}
#endif

bool PictureInPictureBrowserFrameView::HasAnyVisibleContentSettingViews()
    const {}

// Helper functions for testing.
std::vector<gfx::Animation*>
PictureInPictureBrowserFrameView::GetRenderActiveAnimationsForTesting() {}

std::vector<gfx::Animation*>
PictureInPictureBrowserFrameView::GetRenderInactiveAnimationsForTesting() {}

views::View* PictureInPictureBrowserFrameView::GetBackToTabButtonForTesting() {}

views::View* PictureInPictureBrowserFrameView::GetCloseButtonForTesting() {}

views::Label* PictureInPictureBrowserFrameView::GetWindowTitleForTesting() {}

void PictureInPictureBrowserFrameView::OnMouseEnteredOrExitedWindow(
    bool entered) {}

bool PictureInPictureBrowserFrameView::IsOverlayViewVisible() const {}

BEGIN_METADATA()