chromium/ui/views/widget/widget.cc

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

#include "ui/views/widget/widget.h"

#include <algorithm>
#include <set>
#include <utility>

#include "base/auto_reset.h"
#include "base/check_op.h"
#include "base/containers/adapters.h"
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/current_thread.h"
#include "base/trace_event/base_tracing.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/default_style.h"
#include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/l10n/l10n_font_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/base/mojom/ui_base_types.mojom-shared.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/color/color_provider_manager.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/drag_controller.h"
#include "ui/views/event_monitor.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/focus/focus_manager_factory.h"
#include "ui/views/focus/widget_focus_manager.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/any_widget_observer_singleton.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/sublevel_manager.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_deletion_observer.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/widget/widget_removals_observer.h"
#include "ui/views/window/custom_frame_view.h"
#include "ui/views/window/dialog_delegate.h"

#if BUILDFLAG(IS_LINUX)
#include "ui/linux/linux_ui.h"
#endif

#if BUILDFLAG(IS_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif

namespace views {

namespace {

// If |view| has a layer the layer is added to |layers|. Else this recurses
// through the children. This is used to build a list of the layers created by
// views that are direct children of the Widgets layer.
void BuildViewsWithLayers(View* view, View::Views* views) {}

// Create a native widget implementation.
// First, use the supplied one if non-NULL.
// Finally, make a default one.
NativeWidget* CreateNativeWidget(const Widget::InitParams& params,
                                 internal::NativeWidgetDelegate* delegate) {}

void NotifyCaretBoundsChanged(ui::InputMethod* input_method) {}

}  // namespace

// static
Widget::DisableActivationChangeHandlingType
    Widget::g_disable_activation_change_handling_ =;

// A default implementation of WidgetDelegate, used by Widget when no
// WidgetDelegate is supplied.
class DefaultWidgetDelegate : public WidgetDelegate {};

////////////////////////////////////////////////////////////////////////////////
// Widget, PaintAsActiveLock:

Widget::PaintAsActiveLock::PaintAsActiveLock() = default;
Widget::PaintAsActiveLock::~PaintAsActiveLock() = default;

////////////////////////////////////////////////////////////////////////////////
// Widget, PaintAsActiveLockImpl:

class Widget::PaintAsActiveLockImpl : public Widget::PaintAsActiveLock {};

////////////////////////////////////////////////////////////////////////////////
// Widget, InitParams:

Widget::InitParams::InitParams(Type type)
    :{}

Widget::InitParams::InitParams(Ownership ownership, Type type)
    :{}

Widget::InitParams::InitParams(InitParams&& other) = default;

Widget::InitParams::~InitParams() = default;

bool Widget::InitParams::CanActivate() const {}

ui::ZOrderLevel Widget::InitParams::EffectiveZOrderLevel() const {}

bool Widget::InitParams::ShouldInitAsHeadless() const {}

////////////////////////////////////////////////////////////////////////////////
// Widget, public:

Widget::Widget() = default;

Widget::Widget(InitParams params) {}

Widget::~Widget() {}

// static
Widget* Widget::CreateWindowWithParent(WidgetDelegate* delegate,
                                       gfx::NativeView parent,
                                       const gfx::Rect& bounds) {}

Widget* Widget::CreateWindowWithParent(std::unique_ptr<WidgetDelegate> delegate,
                                       gfx::NativeView parent,
                                       const gfx::Rect& bounds) {}

// static
Widget* Widget::CreateWindowWithContext(WidgetDelegate* delegate,
                                        gfx::NativeWindow context,
                                        const gfx::Rect& bounds) {}

// static
Widget* Widget::CreateWindowWithContext(
    std::unique_ptr<WidgetDelegate> delegate,
    gfx::NativeWindow context,
    const gfx::Rect& bounds) {}

// static
Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) {}

// static
Widget* Widget::GetWidgetForNativeWindow(gfx::NativeWindow native_window) {}

// static
Widget* Widget::GetTopLevelWidgetForNativeView(gfx::NativeView native_view) {}

// static
void Widget::GetAllChildWidgets(gfx::NativeView native_view,
                                Widgets* children) {}

// static
void Widget::GetAllOwnedWidgets(gfx::NativeView native_view, Widgets* owned) {}

// static
void Widget::ReparentNativeView(gfx::NativeView native_view,
                                gfx::NativeView new_parent) {}

// static
int Widget::GetLocalizedContentsWidth(int col_resource_id) {}

// static
int Widget::GetLocalizedContentsHeight(int row_resource_id) {}

// static
gfx::Size Widget::GetLocalizedContentsSize(int col_resource_id,
                                           int row_resource_id) {}

// static
bool Widget::RequiresNonClientView(InitParams::Type type) {}

// static
bool Widget::IsWindowCompositingSupported() {}

void Widget::Init(InitParams params) {}

void Widget::ShowEmojiPanel() {}

// Unconverted methods (see header) --------------------------------------------

gfx::NativeView Widget::GetNativeView() const {}

gfx::NativeWindow Widget::GetNativeWindow() const {}

void Widget::AddObserver(WidgetObserver* observer) {}

void Widget::RemoveObserver(WidgetObserver* observer) {}

bool Widget::HasObserver(const WidgetObserver* observer) const {}

void Widget::AddRemovalsObserver(WidgetRemovalsObserver* observer) {}

void Widget::RemoveRemovalsObserver(WidgetRemovalsObserver* observer) {}

bool Widget::HasRemovalsObserver(const WidgetRemovalsObserver* observer) const {}

bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) const {}

void Widget::ViewHierarchyChanged(const ViewHierarchyChangedDetails& details) {}

void Widget::NotifyNativeViewHierarchyWillChange() {}

void Widget::NotifyNativeViewHierarchyChanged() {}

void Widget::NotifyWillRemoveView(View* view) {}

// Converted methods (see header) ----------------------------------------------

Widget* Widget::GetTopLevelWidget() {}

const Widget* Widget::GetTopLevelWidget() const {}

Widget* Widget::GetPrimaryWindowWidget() {}

const Widget* Widget::GetPrimaryWindowWidget() const {}

void Widget::SetContentsView(View* view) {}

View* Widget::GetContentsView() {}

gfx::Rect Widget::GetWindowBoundsInScreen() const {}

gfx::Rect Widget::GetClientAreaBoundsInScreen() const {}

gfx::Rect Widget::GetRestoredBounds() const {}

std::string Widget::GetWorkspace() const {}

void Widget::SetBounds(const gfx::Rect& bounds) {}

void Widget::SetSize(const gfx::Size& size) {}

gfx::Size Widget::GetSize() const {}

gfx::Insets Widget::GetCustomInsetsInDIP() const {}

void Widget::CenterWindow(const gfx::Size& size) {}

void Widget::SetBoundsConstrained(const gfx::Rect& bounds) {}

void Widget::SetVisibilityChangedAnimationsEnabled(bool value) {}

void Widget::SetVisibilityAnimationDuration(const base::TimeDelta& duration) {}

void Widget::SetVisibilityAnimationTransition(VisibilityTransition transition) {}

bool Widget::IsMoveLoopSupported() const {}

Widget::MoveLoopResult Widget::RunMoveLoop(
    const gfx::Vector2d& drag_offset,
    MoveLoopSource source,
    MoveLoopEscapeBehavior escape_behavior) {}

void Widget::EndMoveLoop() {}

void Widget::StackAboveWidget(Widget* widget) {}

void Widget::StackAbove(gfx::NativeView native_view) {}

void Widget::StackAtTop() {}

bool Widget::IsStackedAbove(gfx::NativeView native_view) {}

void Widget::SetShape(std::unique_ptr<ShapeRects> shape) {}

void Widget::CloseWithReason(ClosedReason closed_reason) {}

void Widget::Close() {}

void Widget::CloseNow() {}

bool Widget::IsClosed() const {}

void Widget::Show() {}

void Widget::Hide() {}

void Widget::ShowInactive() {}

void Widget::Activate() {}

void Widget::Deactivate() {}

bool Widget::IsActive() const {}

bool Widget::ShouldViewsStyleFollowWidgetActivation() const {}

void Widget::SetZOrderLevel(ui::ZOrderLevel order) {}

ui::ZOrderLevel Widget::GetZOrderLevel() const {}

void Widget::SetZOrderSublevel(int sublevel) {}

int Widget::GetZOrderSublevel() const {}

void Widget::SetVisibleOnAllWorkspaces(bool always_visible) {}

bool Widget::IsVisibleOnAllWorkspaces() const {}

void Widget::Maximize() {}

void Widget::Minimize() {}

void Widget::Restore() {}

bool Widget::IsMaximized() const {}

bool Widget::IsMinimized() const {}

void Widget::SetFullscreen(bool fullscreen, int64_t target_display_id) {}

bool Widget::IsFullscreen() const {}

void Widget::SetCanAppearInExistingFullscreenSpaces(
    bool can_appear_in_existing_fullscreen_spaces) {}

void Widget::SetOpacity(float opacity) {}

void Widget::SetAspectRatio(const gfx::SizeF& aspect_ratio) {}

void Widget::FlashFrame(bool flash) {}

View* Widget::GetRootView() {}

const View* Widget::GetRootView() const {}

bool Widget::IsVisible() const {}

const ui::ThemeProvider* Widget::GetThemeProvider() const {}

ui::ColorProviderKey::ThemeInitializerSupplier* Widget::GetCustomTheme() const {}

FocusManager* Widget::GetFocusManager() {}

const FocusManager* Widget::GetFocusManager() const {}

ui::InputMethod* Widget::GetInputMethod() {}

SublevelManager* Widget::GetSublevelManager() {}

void Widget::RunShellDrag(View* view,
                          std::unique_ptr<ui::OSExchangeData> data,
                          const gfx::Point& location,
                          int operation,
                          ui::mojom::DragEventSource source) {}

void Widget::CancelShellDrag(View* view) {}

void Widget::SchedulePaintInRect(const gfx::Rect& rect) {}

void Widget::OnRootViewLayoutInvalidated() {}

void Widget::ScheduleLayout() {}

void Widget::SetCursor(const ui::Cursor& cursor) {}

bool Widget::IsMouseEventsEnabled() const {}

void Widget::SetNativeWindowProperty(const char* name, void* value) {}

void* Widget::GetNativeWindowProperty(const char* name) const {}

void Widget::UpdateWindowTitle() {}

void Widget::UpdateWindowIcon() {}

FocusTraversable* Widget::GetFocusTraversable() {}

void Widget::ThemeChanged() {}

void Widget::DeviceScaleFactorChanged(float old_device_scale_factor,
                                      float new_device_scale_factor) {}

void Widget::SetFocusTraversableParent(FocusTraversable* parent) {}

void Widget::SetFocusTraversableParentView(View* parent_view) {}

void Widget::ClearNativeFocus() {}

std::unique_ptr<NonClientFrameView> Widget::CreateNonClientFrameView() {}

bool Widget::ShouldUseNativeFrame() const {}

bool Widget::ShouldWindowContentsBeTransparent() const {}

void Widget::FrameTypeChanged() {}

const ui::Compositor* Widget::GetCompositor() const {}

const ui::Layer* Widget::GetLayer() const {}

void Widget::ReorderNativeViews() {}

void Widget::LayerTreeChanged() {}

const NativeWidget* Widget::native_widget() const {}

NativeWidget* Widget::native_widget() {}

void Widget::SetCapture(View* view) {}

void Widget::ReleaseCapture() {}

bool Widget::HasCapture() {}

TooltipManager* Widget::GetTooltipManager() {}

const TooltipManager* Widget::GetTooltipManager() const {}

gfx::Rect Widget::GetWorkAreaBoundsInScreen() const {}

void Widget::SynthesizeMouseMoveEvent() {}

ui::GestureRecognizer* Widget::GetGestureRecognizer() {}

ui::GestureConsumer* Widget::GetGestureConsumer() {}

void Widget::OnSizeConstraintsChanged() {}

void Widget::OnOwnerClosing() {}

std::string Widget::GetName() const {}

base::CallbackListSubscription Widget::RegisterPaintAsActiveChangedCallback(
    PaintAsActiveCallbackList::CallbackType callback) {}

std::unique_ptr<Widget::PaintAsActiveLock> Widget::LockPaintAsActive() {}

base::WeakPtr<Widget> Widget::GetWeakPtr() {}

bool Widget::ShouldPaintAsActive() const {}

void Widget::OnParentShouldPaintAsActiveChanged() {}

void Widget::NotifyPaintAsActiveChanged() {}

void Widget::SetNativeTheme(ui::NativeTheme* native_theme) {}

int Widget::GetX() const {}

int Widget::GetY() const {}

int Widget::GetWidth() const {}

int Widget::GetHeight() const {}

bool Widget::GetVisible() const {}

void Widget::SetX(int x) {}

void Widget::SetY(int y) {}

void Widget::SetWidth(int width) {}

void Widget::SetHeight(int height) {}

void Widget::SetVisible(bool visible) {}

////////////////////////////////////////////////////////////////////////////////
// Widget, NativeWidgetDelegate implementation:

bool Widget::IsModal() const {}

bool Widget::IsDialogBox() const {}

bool Widget::CanActivate() const {}

bool Widget::IsNativeWidgetInitialized() const {}

bool Widget::OnNativeWidgetActivationChanged(bool active) {}

bool Widget::ShouldHandleNativeWidgetActivationChanged(bool active) {}

void Widget::OnNativeFocus() {}

void Widget::OnNativeBlur() {}

void Widget::OnNativeWidgetVisibilityChanged(bool visible) {}

void Widget::OnNativeWidgetCreated() {}

void Widget::OnNativeWidgetDestroying() {}

void Widget::OnNativeWidgetDestroyed() {}

void Widget::OnNativeWidgetParentChanged(gfx::NativeView parent) {}

gfx::Size Widget::GetMinimumSize() const {}

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

void Widget::OnNativeWidgetMove() {}

void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {}

void Widget::OnNativeWidgetWorkspaceChanged() {}

void Widget::OnNativeWidgetWindowShowStateChanged() {}

void Widget::OnNativeWidgetBeginUserBoundsChange() {}

void Widget::OnNativeWidgetEndUserBoundsChange() {}

void Widget::OnNativeWidgetAddedToCompositor() {}

void Widget::OnNativeWidgetRemovingFromCompositor() {}

bool Widget::HasFocusManager() const {}

void Widget::OnNativeWidgetPaint(const ui::PaintContext& context) {}

int Widget::GetNonClientComponent(const gfx::Point& point) {}

void Widget::OnKeyEvent(ui::KeyEvent* event) {}

// TODO(tdanderson): We should not be calling the OnMouse*() functions on
//                   RootView from anywhere in Widget. Use
//                   SendEventToSink() instead. See crbug.com/348087.
void Widget::OnMouseEvent(ui::MouseEvent* event) {}

void Widget::OnMouseCaptureLost() {}

void Widget::OnScrollEvent(ui::ScrollEvent* event) {}

void Widget::OnGestureEvent(ui::GestureEvent* event) {}

bool Widget::ExecuteCommand(int command_id) {}

bool Widget::HasHitTestMask() const {}

void Widget::GetHitTestMask(SkPath* mask) const {}

Widget* Widget::AsWidget() {}

const Widget* Widget::AsWidget() const {}

bool Widget::SetInitialFocus(ui::WindowShowState show_state) {}

bool Widget::ShouldDescendIntoChildForEventHandling(
    ui::Layer* root_layer,
    gfx::NativeView child,
    ui::Layer* child_layer,
    const gfx::Point& location) {}

void Widget::LayoutRootViewIfNecessary() {}

////////////////////////////////////////////////////////////////////////////////
// Widget, ui::EventSource implementation:
ui::EventSink* Widget::GetEventSink() {}

////////////////////////////////////////////////////////////////////////////////
// Widget, FocusTraversable implementation:

FocusSearch* Widget::GetFocusSearch() {}

FocusTraversable* Widget::GetFocusTraversableParent() {}

View* Widget::GetFocusTraversableParentView() {}

////////////////////////////////////////////////////////////////////////////////
// Widget, ui::NativeThemeObserver implementation:

void Widget::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {}

void Widget::SetColorModeOverride(
    std::optional<ui::ColorProviderKey::ColorMode> color_mode) {}

////////////////////////////////////////////////////////////////////////////////
// Widget, ui::ColorProviderSource:

ui::ColorProviderKey Widget::GetColorProviderKey() const {}

const ui::ColorProvider* Widget::GetColorProvider() const {}

ui::RendererColorMap Widget::GetRendererColorMap(
    ui::ColorProviderKey::ColorMode color_mode,
    ui::ColorProviderKey::ForcedColors forced_colors) const {}

ui::ColorProviderKey Widget::GetColorProviderKeyForTesting() const {}

void Widget::SetCheckParentForFullscreen() {}

void Widget::SetAllowScreenshots(bool allow) {}

bool Widget::AreScreenshotsAllowed() {}

////////////////////////////////////////////////////////////////////////////////
// Widget, protected:

internal::RootView* Widget::CreateRootView() {}

void Widget::DestroyRootView() {}

void Widget::OnDragWillStart() {}

void Widget::OnDragComplete() {}

const ui::NativeTheme* Widget::GetNativeTheme() const {}

////////////////////////////////////////////////////////////////////////////////
// Widget, private:

void Widget::SaveWindowPlacement() {}

void Widget::SaveWindowPlacementIfInitialized() {}

void Widget::SetInitialBounds(const gfx::Rect& bounds) {}

void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds) {}

void Widget::SetParent(Widget* parent) {}

bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds,
                                     ui::WindowShowState* show_state) {}

const View::Views& Widget::GetViewsWithLayers() {}

void Widget::UnlockPaintAsActive() {}

void Widget::ClearFocusFromWidget() {}

void Widget::HandleShowRequested() {}

void Widget::HandleWidgetDestroying() {}

void Widget::HandleWidgetDestroyed() {}

BEGIN_METADATA_BASE()

namespace internal {

////////////////////////////////////////////////////////////////////////////////
// internal::NativeWidgetPrivate, NativeWidget implementation:

internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {}

}  // namespace internal
}  // namespace views

DEFINE_ENUM_CONVERTERS()