|
28 | 28 | #include "content/public/browser/web_contents.h" |
29 | 29 | #include "content/public/browser/web_contents_view.h" |
30 | 30 | #include "skia/ext/image_operations.h" |
| 31 | +#include "ui/aura/client/screen_position_client.h" |
| 32 | +#include "ui/aura/window.h" |
| 33 | +#include "ui/aura/window_tree_host.h" |
31 | 34 | #include "ui/gfx/gdi_util.h" |
32 | 35 | #include "ui/gfx/icon_util.h" |
33 | 36 | #include "ui/views/controls/menu/menu_2.h" |
@@ -144,12 +147,20 @@ void Menu::Popup(int x, int y, content::Shell* shell) { |
144 | 147 | Rebuild(); |
145 | 148 |
|
146 | 149 | // Map point from document to screen. |
147 | | - POINT screen_point = { x, y }; |
148 | | - ClientToScreen((HWND)shell->web_contents()->GetView()->GetNativeView(), |
149 | | - &screen_point); |
150 | | - |
151 | | - menu_->RunMenuAt(gfx::Point(screen_point.x, screen_point.y), |
152 | | - views::Menu2::ALIGN_TOPLEFT); |
| 150 | + gfx::Point screen_point(x, y); |
| 151 | + |
| 152 | + // Convert from content coordinates to window coordinates. |
| 153 | + // This code copied from chrome_web_contents_view_delegate_views.cc |
| 154 | + aura::Window* web_contents_window = |
| 155 | + shell->web_contents()->GetView()->GetNativeView(); |
| 156 | + aura::Window* root_window = web_contents_window->GetRootWindow(); |
| 157 | + aura::client::ScreenPositionClient* screen_position_client = |
| 158 | + aura::client::GetScreenPositionClient(root_window); |
| 159 | + if (screen_position_client) { |
| 160 | + screen_position_client->ConvertPointToScreen(web_contents_window, |
| 161 | + &screen_point); |
| 162 | + } |
| 163 | + menu_->RunMenuAt(screen_point, views::Menu2::ALIGN_TOPLEFT); |
153 | 164 | } |
154 | 165 |
|
155 | 166 | void Menu::Rebuild(const HMENU *parent_menu) { |
|
0 commit comments