#include "chrome/browser/ui/views/omnibox/rounded_omnibox_results_frame.h"
#include "base/feature_list.h"
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "components/omnibox/common/omnibox_features.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/pointer/touch_ui_controller.h"
#include "ui/base/ui_base_features.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/layout/layout_provider.h"
#if defined(USE_AURA)
#include "ui/aura/window.h"
#include "ui/aura/window_targeter.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "ui/views/widget/native_widget_aura.h"
#endif
namespace {
constexpr int kElevation = …;
#if !defined(USE_AURA)
struct WidgetEventPair {
raw_ptr<views::Widget> widget;
std::unique_ptr<ui::MouseEvent> event;
};
#if BUILDFLAG(IS_MAC)
views::Widget* GetImmersiveFullscreenWidgetForEvent(
views::View* this_view,
const ui::MouseEvent* this_event) {
views::Widget* parent_widget = this_view->GetWidget()->parent();
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(
parent_widget->GetNativeWindow());
if (browser_view->overlay_widget() != parent_widget) {
return nullptr;
}
{
gfx::Point event_location = this_event->location();
views::View::ConvertPointToScreen(this_view, &event_location);
views::View::ConvertPointFromScreen(browser_view->GetLocationBarView(),
&event_location);
if (browser_view->GetLocationBarView()->HitTestPoint(event_location)) {
return browser_view->overlay_widget();
}
}
{
gfx::Point event_location = this_event->location();
views::View::ConvertPointToScreen(this_view, &event_location);
views::View::ConvertPointFromScreen(browser_view->contents_container(),
&event_location);
if (browser_view->contents_container()->HitTestPoint(event_location)) {
return browser_view->GetWidget();
}
}
if (browser_view->tab_overlay_widget()) {
return browser_view->tab_overlay_widget();
}
return browser_view->overlay_widget();
}
#endif
WidgetEventPair GetParentWidgetAndEvent(views::View* this_view,
const ui::MouseEvent* this_event) {
views::Widget* this_widget = this_view->GetWidget();
views::Widget* parent_widget = this_widget->parent();
std::unique_ptr<ui::MouseEvent> event(
static_cast<ui::MouseEvent*>(this_event->Clone().release()));
if (!parent_widget)
return {nullptr, std::move(event)};
#if BUILDFLAG(IS_MAC)
views::Widget* top_level =
GetImmersiveFullscreenWidgetForEvent(this_view, this_event)
?: parent_widget->GetTopLevelWidgetForNativeView(
parent_widget->GetNativeView());
#else
views::Widget* top_level = parent_widget->GetTopLevelWidgetForNativeView(
parent_widget->GetNativeView());
#endif
DCHECK_NE(this_widget, top_level);
if (!top_level)
return {nullptr, std::move(event)};
gfx::Point event_location = this_event->location();
views::View::ConvertPointToScreen(this_view, &event_location);
views::View::ConvertPointFromScreen(top_level->GetRootView(),
&event_location);
event->set_location(event_location);
return {top_level, std::move(event)};
}
#endif
class TopBackgroundView : public views::View { … };
BEGIN_METADATA(…)
gfx::Insets GetContentInsets() { … }
}
RoundedOmniboxResultsFrame::RoundedOmniboxResultsFrame(
views::View* contents,
LocationBarView* location_bar)
: … { … }
RoundedOmniboxResultsFrame::~RoundedOmniboxResultsFrame() = default;
void RoundedOmniboxResultsFrame::OnBeforeWidgetInit(
views::Widget::InitParams* params,
views::Widget* widget) { … }
int RoundedOmniboxResultsFrame::GetNonResultSectionHeight() { … }
gfx::Insets RoundedOmniboxResultsFrame::GetLocationBarAlignmentInsets() { … }
gfx::Insets RoundedOmniboxResultsFrame::GetShadowInsets() { … }
void RoundedOmniboxResultsFrame::Layout(PassKey) { … }
void RoundedOmniboxResultsFrame::AddedToWidget() { … }
#if !defined(USE_AURA)
void RoundedOmniboxResultsFrame::OnMouseMoved(const ui::MouseEvent& event) {
auto pair = GetParentWidgetAndEvent(this, &event);
if (pair.widget)
pair.widget->OnMouseEvent(pair.event.get());
}
void RoundedOmniboxResultsFrame::OnMouseEvent(ui::MouseEvent* event) {
auto pair = GetParentWidgetAndEvent(this, event);
if (pair.widget)
pair.widget->OnMouseEvent(pair.event.get());
}
#endif
BEGIN_METADATA(…)