OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/menu/menu_controller.h" | 5 #include "ui/views/controls/menu/menu_controller.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "ui/views/mouse_constants.h" | 32 #include "ui/views/mouse_constants.h" |
33 #include "ui/views/view.h" | 33 #include "ui/views/view.h" |
34 #include "ui/views/view_constants.h" | 34 #include "ui/views/view_constants.h" |
35 #include "ui/views/views_delegate.h" | 35 #include "ui/views/views_delegate.h" |
36 #include "ui/views/widget/root_view.h" | 36 #include "ui/views/widget/root_view.h" |
37 #include "ui/views/widget/tooltip_manager.h" | 37 #include "ui/views/widget/tooltip_manager.h" |
38 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
39 | 39 |
40 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
41 #include "ui/base/win/internal_constants.h" | 41 #include "ui/base/win/internal_constants.h" |
42 #include "ui/gfx/win/dpi.h" | |
42 #include "ui/views/win/hwnd_util.h" | 43 #include "ui/views/win/hwnd_util.h" |
43 #endif | 44 #endif |
44 | 45 |
45 using base::Time; | 46 using base::Time; |
46 using base::TimeDelta; | 47 using base::TimeDelta; |
47 using ui::OSExchangeData; | 48 using ui::OSExchangeData; |
48 | 49 |
49 // Period of the scroll timer (in milliseconds). | 50 // Period of the scroll timer (in milliseconds). |
50 static const int kScrollTimerMS = 30; | 51 static const int kScrollTimerMS = 30; |
51 | 52 |
(...skipping 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2044 gfx::Point screen_loc(event.location()); | 2045 gfx::Point screen_loc(event.location()); |
2045 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); | 2046 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); |
2046 gfx::NativeView native_view = source->GetWidget()->GetNativeView(); | 2047 gfx::NativeView native_view = source->GetWidget()->GetNativeView(); |
2047 if (!native_view) | 2048 if (!native_view) |
2048 return; | 2049 return; |
2049 | 2050 |
2050 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); | 2051 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); |
2051 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); | 2052 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); |
2052 | 2053 |
2053 #if defined(OS_WIN) | 2054 #if defined(OS_WIN) |
2055 // Convert screen_loc to pixels for the Win32 API's like WindowFromPoint, | |
2056 // PostMessage/SendMessage to work correctly. These API's expect the | |
2057 // coordinates to be in pixels. | |
2058 gfx::Point screen_loc_pixels = gfx::win::DIPToScreenPoint(screen_loc); | |
sky
2014/06/19 15:33:32
nit: move into conditional block below, it's only
ananta
2014/06/19 18:45:26
Done.
| |
2054 // PostMessage() to metro windows isn't allowed (access will be denied). Don't | 2059 // PostMessage() to metro windows isn't allowed (access will be denied). Don't |
2055 // try to repost with Win32 if the window under the mouse press is in metro. | 2060 // try to repost with Win32 if the window under the mouse press is in metro. |
2056 if (!ViewsDelegate::views_delegate || | 2061 if (!ViewsDelegate::views_delegate || |
2057 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) { | 2062 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) { |
2058 HWND target_window = window ? HWNDForNativeWindow(window) : | 2063 HWND target_window = window ? HWNDForNativeWindow(window) : |
2059 WindowFromPoint(screen_loc.ToPOINT()); | 2064 WindowFromPoint(screen_loc_pixels.ToPOINT()); |
2060 HWND source_window = HWNDForNativeView(native_view); | 2065 HWND source_window = HWNDForNativeView(native_view); |
2061 if (!target_window || !source_window || | 2066 if (!target_window || !source_window || |
2062 GetWindowThreadProcessId(source_window, NULL) != | 2067 GetWindowThreadProcessId(source_window, NULL) != |
2063 GetWindowThreadProcessId(target_window, NULL)) { | 2068 GetWindowThreadProcessId(target_window, NULL)) { |
2064 // Even though we have mouse capture, windows generates a mouse event if | 2069 // Even though we have mouse capture, windows generates a mouse event if |
2065 // the other window is in a separate thread. Only repost an event if | 2070 // the other window is in a separate thread. Only repost an event if |
2066 // |target_window| and |source_window| were created on the same thread, | 2071 // |target_window| and |source_window| were created on the same thread, |
2067 // else double events can occur and lead to bad behavior. | 2072 // else double events can occur and lead to bad behavior. |
2068 return; | 2073 return; |
2069 } | 2074 } |
2070 | 2075 |
2071 // Determine whether the click was in the client area or not. | 2076 // Determine whether the click was in the client area or not. |
2072 // NOTE: WM_NCHITTEST coordinates are relative to the screen. | 2077 // NOTE: WM_NCHITTEST coordinates are relative to the screen. |
2073 LPARAM coords = MAKELPARAM(screen_loc.x(), screen_loc.y()); | 2078 LPARAM coords = MAKELPARAM(screen_loc_pixels.x(), screen_loc_pixels.y()); |
2074 LRESULT nc_hit_result = SendMessage(target_window, WM_NCHITTEST, 0, coords); | 2079 LRESULT nc_hit_result = SendMessage(target_window, WM_NCHITTEST, 0, coords); |
2075 const bool client_area = nc_hit_result == HTCLIENT; | 2080 const bool client_area = nc_hit_result == HTCLIENT; |
2076 | 2081 |
2077 // TODO(sky): this isn't right. The event to generate should correspond with | 2082 // TODO(sky): this isn't right. The event to generate should correspond with |
2078 // the event we just got. MouseEvent only tells us what is down, which may | 2083 // the event we just got. MouseEvent only tells us what is down, which may |
2079 // differ. Need to add ability to get changed button from MouseEvent. | 2084 // differ. Need to add ability to get changed button from MouseEvent. |
2080 int event_type; | 2085 int event_type; |
2081 int flags = event.flags(); | 2086 int flags = event.flags(); |
2082 if (flags & ui::EF_LEFT_MOUSE_BUTTON) { | 2087 if (flags & ui::EF_LEFT_MOUSE_BUTTON) { |
2083 event_type = client_area ? WM_LBUTTONDOWN : WM_NCLBUTTONDOWN; | 2088 event_type = client_area ? WM_LBUTTONDOWN : WM_NCLBUTTONDOWN; |
2084 } else if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) { | 2089 } else if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) { |
2085 event_type = client_area ? WM_MBUTTONDOWN : WM_NCMBUTTONDOWN; | 2090 event_type = client_area ? WM_MBUTTONDOWN : WM_NCMBUTTONDOWN; |
2086 } else if (flags & ui::EF_RIGHT_MOUSE_BUTTON) { | 2091 } else if (flags & ui::EF_RIGHT_MOUSE_BUTTON) { |
2087 event_type = client_area ? WM_RBUTTONDOWN : WM_NCRBUTTONDOWN; | 2092 event_type = client_area ? WM_RBUTTONDOWN : WM_NCRBUTTONDOWN; |
2088 } else { | 2093 } else { |
2089 NOTREACHED(); | 2094 NOTREACHED(); |
2090 return; | 2095 return; |
2091 } | 2096 } |
2092 | 2097 |
2093 int window_x = screen_loc.x(); | 2098 int window_x = screen_loc_pixels.x(); |
2094 int window_y = screen_loc.y(); | 2099 int window_y = screen_loc_pixels.y(); |
2095 if (client_area) { | 2100 if (client_area) { |
2096 POINT pt = { window_x, window_y }; | 2101 POINT pt = { window_x, window_y }; |
2097 ScreenToClient(target_window, &pt); | 2102 ScreenToClient(target_window, &pt); |
2098 window_x = pt.x; | 2103 window_x = pt.x; |
2099 window_y = pt.y; | 2104 window_y = pt.y; |
2100 } | 2105 } |
2101 | 2106 |
2102 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result; | 2107 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result; |
2103 LPARAM window_coords = MAKELPARAM(window_x, window_y); | 2108 LPARAM window_coords = MAKELPARAM(window_x, window_y); |
2104 PostMessage(target_window, event_type, target, window_coords); | 2109 PostMessage(target_window, event_type, target, window_coords); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2286 } | 2291 } |
2287 } | 2292 } |
2288 | 2293 |
2289 gfx::Screen* MenuController::GetScreen() { | 2294 gfx::Screen* MenuController::GetScreen() { |
2290 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; | 2295 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; |
2291 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) | 2296 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) |
2292 : gfx::Screen::GetNativeScreen(); | 2297 : gfx::Screen::GetNativeScreen(); |
2293 } | 2298 } |
2294 | 2299 |
2295 } // namespace views | 2300 } // namespace views |
OLD | NEW |