Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: ui/views/controls/menu/menu_controller.cc

Issue 341763002: Ensure that mouse events on Windows reposted by the menu_controller are converted to pixel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 30 matching lines...) Expand all
82 // Returns true if |menu| doesn't have a mnemonic and first character of the its 83 // Returns true if |menu| doesn't have a mnemonic and first character of the its
83 // title is |key|. 84 // title is |key|.
84 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) { 85 bool TitleMatchesMnemonic(MenuItemView* menu, base::char16 key) {
85 if (menu->GetMnemonic()) 86 if (menu->GetMnemonic())
86 return false; 87 return false;
87 88
88 base::string16 lower_title = base::i18n::ToLower(menu->title()); 89 base::string16 lower_title = base::i18n::ToLower(menu->title());
89 return !lower_title.empty() && lower_title[0] == key; 90 return !lower_title.empty() && lower_title[0] == key;
90 } 91 }
91 92
93 // Returns the window and the screen location for the coordinates identified
94 // by |event|. The window is returned in the output parameter |window| and
95 // the screen location is returned in the output parameter |screen_location|.
96 void PlatformGetWindowAtLocation(const ui::LocatedEvent& event,
97 SubmenuView* source,
98 gfx::NativeView native_view,
99 gfx::NativeWindow* window,
100 gfx::Point* screen_location) {
101 gfx::Point screen_loc(event.location());
102 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc);
103 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view);
104 #if defined(OS_WIN)
105 // On Windows convert the coordinates from DIP to pixel to ensure that we
106 // get the correct window.
107 screen_loc = gfx::win::DIPToScreenPoint(screen_loc);
108 #endif
109 *window = screen->GetWindowAtScreenPoint(screen_loc);
sky 2014/06/18 22:20:26 Something seems wrong here. Why does GetWindowAtSc
oshima 2014/06/18 22:27:51 Yes, both must be in DIP.
ananta 2014/06/18 22:57:10 I updated the patch to fix ScreenWin::GetWindowAtS
110 *screen_location = screen_loc;
111 }
112
92 } // namespace 113 } // namespace
93 114
94 // Returns the first descendant of |view| that is hot tracked. 115 // Returns the first descendant of |view| that is hot tracked.
95 static CustomButton* GetFirstHotTrackedView(View* view) { 116 static CustomButton* GetFirstHotTrackedView(View* view) {
96 if (!view) 117 if (!view)
97 return NULL; 118 return NULL;
98 CustomButton* button = CustomButton::AsCustomButton(view); 119 CustomButton* button = CustomButton::AsCustomButton(view);
99 if (button) { 120 if (button) {
100 if (button->IsHotTracked()) 121 if (button->IsHotTracked())
101 return button; 122 return button;
(...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 // We some times get an event after closing all the menus. Ignore it. Make 2056 // We some times get an event after closing all the menus. Ignore it. Make
2036 // sure the menu is in fact not visible. If the menu is visible, then 2057 // sure the menu is in fact not visible. If the menu is visible, then
2037 // we're in a bad state where we think the menu isn't visibile but it is. 2058 // we're in a bad state where we think the menu isn't visibile but it is.
2038 DCHECK(!source->GetWidget()->IsVisible()); 2059 DCHECK(!source->GetWidget()->IsVisible());
2039 return; 2060 return;
2040 } 2061 }
2041 2062
2042 state_.item->GetRootMenuItem()->GetSubmenu()->ReleaseCapture(); 2063 state_.item->GetRootMenuItem()->GetSubmenu()->ReleaseCapture();
2043 #endif 2064 #endif
2044 2065
2045 gfx::Point screen_loc(event.location());
2046 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc);
2047 gfx::NativeView native_view = source->GetWidget()->GetNativeView(); 2066 gfx::NativeView native_view = source->GetWidget()->GetNativeView();
2048 if (!native_view) 2067 if (!native_view)
2049 return; 2068 return;
2050 2069
2051 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); 2070 gfx::NativeWindow window = NULL;
2052 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); 2071 gfx::Point screen_loc;
2053 2072
2073 PlatformGetWindowAtLocation(event, source, native_view, &window,
2074 &screen_loc);
2054 #if defined(OS_WIN) 2075 #if defined(OS_WIN)
2055 // PostMessage() to metro windows isn't allowed (access will be denied). Don't 2076 // PostMessage() to metro windows isn't allowed (access will be denied). Don't
2056 // try to repost with Win32 if the window under the mouse press is in metro. 2077 // try to repost with Win32 if the window under the mouse press is in metro.
2057 if (!ViewsDelegate::views_delegate || 2078 if (!ViewsDelegate::views_delegate ||
2058 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) { 2079 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) {
2059 HWND target_window = window ? HWNDForNativeWindow(window) : 2080 HWND target_window = window ? HWNDForNativeWindow(window) :
2060 WindowFromPoint(screen_loc.ToPOINT()); 2081 WindowFromPoint(screen_loc.ToPOINT());
2061 HWND source_window = HWNDForNativeView(native_view); 2082 HWND source_window = HWNDForNativeView(native_view);
2062 if (!target_window || !source_window || 2083 if (!target_window || !source_window ||
2063 GetWindowThreadProcessId(source_window, NULL) != 2084 GetWindowThreadProcessId(source_window, NULL) !=
2064 GetWindowThreadProcessId(target_window, NULL)) { 2085 GetWindowThreadProcessId(target_window, NULL)) {
2065 // Even though we have mouse capture, windows generates a mouse event if 2086 // Even though we have mouse capture, windows generates a mouse event if
2066 // the other window is in a separate thread. Only repost an event if 2087 // the other window is in a separate thread. Only repost an event if
2067 // |target_window| and |source_window| were created on the same thread, 2088 // |target_window| and |source_window| were created on the same thread,
2068 // else double events can occur and lead to bad behavior. 2089 // else double events can occur and lead to bad behavior.
2069 return; 2090 return;
2070 } 2091 }
2071
2072 // Determine whether the click was in the client area or not. 2092 // Determine whether the click was in the client area or not.
2073 // NOTE: WM_NCHITTEST coordinates are relative to the screen. 2093 // NOTE: WM_NCHITTEST coordinates are relative to the screen.
2074 LPARAM coords = MAKELPARAM(screen_loc.x(), screen_loc.y()); 2094 LPARAM coords = MAKELPARAM(screen_loc.x(), screen_loc.y());
2075 LRESULT nc_hit_result = SendMessage(target_window, WM_NCHITTEST, 0, coords); 2095 LRESULT nc_hit_result = SendMessage(target_window, WM_NCHITTEST, 0, coords);
2076 const bool client_area = nc_hit_result == HTCLIENT; 2096 const bool client_area = nc_hit_result == HTCLIENT;
2077 2097
2078 // TODO(sky): this isn't right. The event to generate should correspond with 2098 // TODO(sky): this isn't right. The event to generate should correspond with
2079 // the event we just got. MouseEvent only tells us what is down, which may 2099 // the event we just got. MouseEvent only tells us what is down, which may
2080 // differ. Need to add ability to get changed button from MouseEvent. 2100 // differ. Need to add ability to get changed button from MouseEvent.
2081 int event_type; 2101 int event_type;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 } 2307 }
2288 } 2308 }
2289 2309
2290 gfx::Screen* MenuController::GetScreen() { 2310 gfx::Screen* MenuController::GetScreen() {
2291 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; 2311 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL;
2292 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) 2312 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
2293 : gfx::Screen::GetNativeScreen(); 2313 : gfx::Screen::GetNativeScreen();
2294 } 2314 }
2295 2315
2296 } // namespace views 2316 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698