@@ -29,6 +29,35 @@ namespace {
2929// Value from the spec controlling appearance of the shadow.
3030constexpr int kElevation = 16 ;
3131
32+ #if !defined(USE_AURA)
33+
34+ struct WidgetEventPair {
35+ views::Widget* widget;
36+ ui::MouseEvent event;
37+ };
38+
39+ WidgetEventPair GetParentWidgetAndEvent (views::View* this_view,
40+ const ui::MouseEvent* this_event) {
41+ views::Widget* this_widget = this_view->GetWidget ();
42+ views::Widget* parent_widget =
43+ this_widget->GetTopLevelWidgetForNativeView (this_widget->GetNativeView ());
44+ DCHECK_NE (this_widget, parent_widget);
45+ if (!parent_widget)
46+ return {nullptr , *this_event};
47+
48+ gfx::Point event_location = this_event->location ();
49+ views::View::ConvertPointToScreen (this_view, &event_location);
50+ views::View::ConvertPointFromScreen (parent_widget->GetRootView (),
51+ &event_location);
52+
53+ ui::MouseEvent parent_event (*this_event);
54+ parent_event.set_location (event_location);
55+
56+ return {parent_widget, parent_event};
57+ }
58+
59+ #endif // !USE_AURA
60+
3261// View at the top of the frame which paints transparent pixels to make a hole
3362// so that the location bar shows through.
3463class TopBackgroundView : public views ::View {
@@ -46,40 +75,27 @@ class TopBackgroundView : public views::View {
4675 // done with an event targeter set up in
4776 // RoundedOmniboxResultsFrame::AddedToWidget(), below.
4877 private:
49- struct OmniboxWidgetEventPair {
50- views::Widget* widget;
51- ui::MouseEvent event;
52- };
53-
54- OmniboxWidgetEventPair GetOmniboxWidgetAndEvent (const ui::MouseEvent* event) {
55- views::Widget* omnibox_widget = GetWidget ()->GetTopLevelWidgetForNativeView (
56- GetWidget ()->GetNativeView ());
57- DCHECK_NE (GetWidget (), omnibox_widget);
58-
59- gfx::Point event_location = event->location ();
60- views::View::ConvertPointToScreen (this , &event_location);
61- views::View::ConvertPointFromScreen (omnibox_widget->GetRootView (),
62- &event_location);
63-
64- ui::MouseEvent omnibox_event (*event);
65- omnibox_event.set_location (event_location);
66-
67- return {omnibox_widget, omnibox_event};
78+ // Note that mouse moved events can be dispatched through OnMouseEvent, but
79+ // RootView directly calls OnMouseMoved as well, so override OnMouseMoved as
80+ // well to catch 'em all.
81+ void OnMouseMoved (const ui::MouseEvent& event) override {
82+ auto pair = GetParentWidgetAndEvent (this , &event);
83+ pair.widget ->OnMouseEvent (&pair.event );
6884 }
6985
7086 void OnMouseEvent (ui::MouseEvent* event) override {
71- auto pair = GetOmniboxWidgetAndEvent ( event);
87+ auto pair = GetParentWidgetAndEvent ( this , event);
7288 pair.widget ->OnMouseEvent (&pair.event );
7389 }
7490
7591 gfx::NativeCursor GetCursor (const ui::MouseEvent& event) override {
76- auto pair = GetOmniboxWidgetAndEvent ( &event);
92+ auto pair = GetParentWidgetAndEvent ( this , &event);
7793 views::View* omnibox_view =
7894 pair.widget ->GetRootView ()->GetEventHandlerForPoint (
7995 pair.event .location ());
8096 return omnibox_view->GetCursor (pair.event );
8197 }
82- #endif // !AURA
98+ #endif // !USE_AURA
8399};
84100
85101// Insets used to position |contents_| within |contents_host_|.
@@ -200,5 +216,26 @@ void RoundedOmniboxResultsFrame::AddedToWidget() {
200216 auto results_targeter = std::make_unique<aura::WindowTargeter>();
201217 results_targeter->SetInsets (GetInsets () + GetContentInsets ());
202218 GetWidget ()->GetNativeWindow ()->SetEventTargeter (std::move (results_targeter));
203- #endif
219+ #endif // USE_AURA
220+ }
221+
222+ // Note that these two functions are only called for the shadow area, as both
223+ // the omnibox proper and the results list have their own mouse handling.
224+ #if !defined(USE_AURA)
225+
226+ // Note that mouse moved events can be dispatched through OnMouseEvent, but
227+ // RootView directly calls OnMouseMoved as well, so override OnMouseMoved as
228+ // well to catch 'em all.
229+ void RoundedOmniboxResultsFrame::OnMouseMoved (const ui::MouseEvent& event) {
230+ auto pair = GetParentWidgetAndEvent (this , &event);
231+ if (pair.widget )
232+ pair.widget ->OnMouseEvent (&pair.event );
233+ }
234+
235+ void RoundedOmniboxResultsFrame::OnMouseEvent (ui::MouseEvent* event) {
236+ auto pair = GetParentWidgetAndEvent (this , event);
237+ if (pair.widget )
238+ pair.widget ->OnMouseEvent (&pair.event );
204239}
240+
241+ #endif // !USE_AURA
0 commit comments