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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 2756893002: Add Keyboard Latency UMA Metrics. (Closed)
Patch Set: Restrict to RawKeyDown and Char events on Android & Mac Created 3 years, 7 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
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 "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #import <objc/runtime.h> 8 #import <objc/runtime.h>
9 #include <OpenGL/gl.h> 9 #include <OpenGL/gl.h>
10 #include <QuartzCore/QuartzCore.h> 10 #include <QuartzCore/QuartzCore.h>
(...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 return; 2103 return;
2104 } 2104 }
2105 2105
2106 // Don't cancel child popups; the key events are probably what's triggering 2106 // Don't cancel child popups; the key events are probably what's triggering
2107 // the popup in the first place. 2107 // the popup in the first place.
2108 2108
2109 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; 2109 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_;
2110 DCHECK(widgetHost); 2110 DCHECK(widgetHost);
2111 2111
2112 NativeWebKeyboardEvent event(theEvent); 2112 NativeWebKeyboardEvent event(theEvent);
2113 ui::LatencyInfo latency_info;
2114 if (event.GetType() == blink::WebInputEvent::kRawKeyDown ||
2115 event.GetType() == blink::WebInputEvent::kChar) {
2116 latency_info.set_source_event_type(ui::SourceEventType::KEY_PRESS);
2117 }
2118
2119 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
2113 2120
2114 // Force fullscreen windows to close on Escape so they won't keep the keyboard 2121 // Force fullscreen windows to close on Escape so they won't keep the keyboard
2115 // grabbed or be stuck onscreen if the renderer is hanging. 2122 // grabbed or be stuck onscreen if the renderer is hanging.
2116 if (event.GetType() == NativeWebKeyboardEvent::kRawKeyDown && 2123 if (event.GetType() == NativeWebKeyboardEvent::kRawKeyDown &&
2117 event.windows_key_code == ui::VKEY_ESCAPE && 2124 event.windows_key_code == ui::VKEY_ESCAPE &&
2118 renderWidgetHostView_->pepper_fullscreen_window()) { 2125 renderWidgetHostView_->pepper_fullscreen_window()) {
2119 RenderWidgetHostViewMac* parent = 2126 RenderWidgetHostViewMac* parent =
2120 renderWidgetHostView_->fullscreen_parent_host_view(); 2127 renderWidgetHostView_->fullscreen_parent_host_view();
2121 if (parent) 2128 if (parent)
2122 parent->cocoa_view()->suppressNextEscapeKeyUp_ = YES; 2129 parent->cocoa_view()->suppressNextEscapeKeyUp_ = YES;
(...skipping 19 matching lines...) Expand all
2142 // otherwise we might get an event from releasing the return key in the 2149 // otherwise we might get an event from releasing the return key in the
2143 // omnibox (http://crbug.com/338736). 2150 // omnibox (http://crbug.com/338736).
2144 if ([theEvent type] == NSKeyUp) { 2151 if ([theEvent type] == NSKeyUp) {
2145 auto numErased = keyDownCodes_.erase([theEvent keyCode]); 2152 auto numErased = keyDownCodes_.erase([theEvent keyCode]);
2146 if (numErased < 1) 2153 if (numErased < 1)
2147 return; 2154 return;
2148 } 2155 }
2149 2156
2150 // We only handle key down events and just simply forward other events. 2157 // We only handle key down events and just simply forward other events.
2151 if ([theEvent type] != NSKeyDown) { 2158 if ([theEvent type] != NSKeyDown) {
2152 widgetHost->ForwardKeyboardEvent(event); 2159 widgetHost->ForwardKeyboardEventWithLatencyInfo(event, latency_info);
2153 2160
2154 // Possibly autohide the cursor. 2161 // Possibly autohide the cursor.
2155 if ([self shouldAutohideCursorForEvent:theEvent]) 2162 if ([self shouldAutohideCursorForEvent:theEvent])
2156 [NSCursor setHiddenUntilMouseMoves:YES]; 2163 [NSCursor setHiddenUntilMouseMoves:YES];
2157 2164
2158 return; 2165 return;
2159 } 2166 }
2160 2167
2161 keyDownCodes_.insert([theEvent keyCode]); 2168 keyDownCodes_.insert([theEvent keyCode]);
2162 2169
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY 2204 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY
2198 // while an input method is composing or inserting a text. 2205 // while an input method is composing or inserting a text.
2199 // Gmail checks this code in its onkeydown handler to stop auto-completing 2206 // Gmail checks this code in its onkeydown handler to stop auto-completing
2200 // e-mail addresses while composing a CJK text. 2207 // e-mail addresses while composing a CJK text.
2201 // If the text to be inserted has only one character, then we don't need this 2208 // If the text to be inserted has only one character, then we don't need this
2202 // trick, because we'll send the text as a key press event instead. 2209 // trick, because we'll send the text as a key press event instead.
2203 if (hasMarkedText_ || oldHasMarkedText || textToBeInserted_.length() > 1) { 2210 if (hasMarkedText_ || oldHasMarkedText || textToBeInserted_.length() > 1) {
2204 NativeWebKeyboardEvent fakeEvent = event; 2211 NativeWebKeyboardEvent fakeEvent = event;
2205 fakeEvent.windows_key_code = 0xE5; // VKEY_PROCESSKEY 2212 fakeEvent.windows_key_code = 0xE5; // VKEY_PROCESSKEY
2206 fakeEvent.skip_in_browser = true; 2213 fakeEvent.skip_in_browser = true;
2207 widgetHost->ForwardKeyboardEvent(fakeEvent); 2214 widgetHost->ForwardKeyboardEventWithLatencyInfo(fakeEvent, latency_info);
2208 // If this key event was handled by the input method, but 2215 // If this key event was handled by the input method, but
2209 // -doCommandBySelector: (invoked by the call to -interpretKeyEvents: above) 2216 // -doCommandBySelector: (invoked by the call to -interpretKeyEvents: above)
2210 // enqueued edit commands, then in order to let webkit handle them 2217 // enqueued edit commands, then in order to let webkit handle them
2211 // correctly, we need to send the real key event and corresponding edit 2218 // correctly, we need to send the real key event and corresponding edit
2212 // commands after processing the input method result. 2219 // commands after processing the input method result.
2213 // We shouldn't do this if a new marked text was set by the input method, 2220 // We shouldn't do this if a new marked text was set by the input method,
2214 // otherwise the new marked text might be cancelled by webkit. 2221 // otherwise the new marked text might be cancelled by webkit.
2215 if (hasEditCommands_ && !hasMarkedText_) 2222 if (hasEditCommands_ && !hasMarkedText_)
2216 delayEventUntilAfterImeCompostion = YES; 2223 delayEventUntilAfterImeCompostion = YES;
2217 } else { 2224 } else {
2218 widgetHost->ForwardKeyboardEventWithCommands(event, &editCommands_); 2225 widgetHost->ForwardKeyboardEventWithCommands(event, latency_info,
2226 &editCommands_);
2219 } 2227 }
2220 2228
2221 // Calling ForwardKeyboardEvent() could have destroyed the widget. When the 2229 // Calling ForwardKeyboardEventWithCommands() could have destroyed the
2222 // widget was destroyed, |renderWidgetHostView_->render_widget_host_| will 2230 // widget. When the widget was destroyed,
2223 // be set to NULL. So we check it here and return immediately if it's NULL. 2231 // |renderWidgetHostView_->render_widget_host_| will be set to NULL. So we
2232 // check it here and return immediately if it's NULL.
2224 if (!renderWidgetHostView_->render_widget_host_) 2233 if (!renderWidgetHostView_->render_widget_host_)
2225 return; 2234 return;
2226 2235
2227 // Then send keypress and/or composition related events. 2236 // Then send keypress and/or composition related events.
2228 // If there was a marked text or the text to be inserted is longer than 1 2237 // If there was a marked text or the text to be inserted is longer than 1
2229 // character, then we send the text by calling FinishComposingText(). 2238 // character, then we send the text by calling FinishComposingText().
2230 // Otherwise, if the text to be inserted only contains 1 character, then we 2239 // Otherwise, if the text to be inserted only contains 1 character, then we
2231 // can just send a keypress event which is fabricated by changing the type of 2240 // can just send a keypress event which is fabricated by changing the type of
2232 // the keydown event, so that we can retain all necessary informations, such 2241 // the keydown event, so that we can retain all necessary informations, such
2233 // as unmodifiedText, etc. And we need to set event.skip_in_browser to true to 2242 // as unmodifiedText, etc. And we need to set event.skip_in_browser to true to
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 // finish current composition session but still wants the application to 2281 // finish current composition session but still wants the application to
2273 // handle the key event. See http://crbug.com/48161 for reference. 2282 // handle the key event. See http://crbug.com/48161 for reference.
2274 if (delayEventUntilAfterImeCompostion) { 2283 if (delayEventUntilAfterImeCompostion) {
2275 // If |delayEventUntilAfterImeCompostion| is YES, then a fake key down event 2284 // If |delayEventUntilAfterImeCompostion| is YES, then a fake key down event
2276 // with windowsKeyCode == 0xE5 has already been sent to webkit. 2285 // with windowsKeyCode == 0xE5 has already been sent to webkit.
2277 // So before sending the real key down event, we need to send a fake key up 2286 // So before sending the real key down event, we need to send a fake key up
2278 // event to balance it. 2287 // event to balance it.
2279 NativeWebKeyboardEvent fakeEvent = event; 2288 NativeWebKeyboardEvent fakeEvent = event;
2280 fakeEvent.SetType(blink::WebInputEvent::kKeyUp); 2289 fakeEvent.SetType(blink::WebInputEvent::kKeyUp);
2281 fakeEvent.skip_in_browser = true; 2290 fakeEvent.skip_in_browser = true;
2282 widgetHost->ForwardKeyboardEvent(fakeEvent); 2291 widgetHost->ForwardKeyboardEventWithLatencyInfo(fakeEvent, latency_info);
2283 // Not checking |renderWidgetHostView_->render_widget_host_| here because 2292 // Not checking |renderWidgetHostView_->render_widget_host_| here because
2284 // a key event with |skip_in_browser| == true won't be handled by browser, 2293 // a key event with |skip_in_browser| == true won't be handled by browser,
2285 // thus it won't destroy the widget. 2294 // thus it won't destroy the widget.
2286 2295
2287 widgetHost->ForwardKeyboardEventWithCommands(event, &editCommands_); 2296 widgetHost->ForwardKeyboardEventWithCommands(event, latency_info,
2297 &editCommands_);
2288 2298
2289 // Calling ForwardKeyboardEvent() could have destroyed the widget. When the 2299 // Calling ForwardKeyboardEventWithCommands() could have destroyed the
2290 // widget was destroyed, |renderWidgetHostView_->render_widget_host_| will 2300 // widget. When the widget was destroyed,
2291 // be set to NULL. So we check it here and return immediately if it's NULL. 2301 // |renderWidgetHostView_->render_widget_host_| will be set to NULL. So we
2302 // check it here and return immediately if it's NULL.
2292 if (!renderWidgetHostView_->render_widget_host_) 2303 if (!renderWidgetHostView_->render_widget_host_)
2293 return; 2304 return;
2294 } 2305 }
2295 2306
2296 const NSUInteger kCtrlCmdKeyMask = NSControlKeyMask | NSCommandKeyMask; 2307 const NSUInteger kCtrlCmdKeyMask = NSControlKeyMask | NSCommandKeyMask;
2297 // Only send a corresponding key press event if there is no marked text. 2308 // Only send a corresponding key press event if there is no marked text.
2298 if (!hasMarkedText_) { 2309 if (!hasMarkedText_) {
2299 if (!textInserted && textToBeInserted_.length() == 1) { 2310 if (!textInserted && textToBeInserted_.length() == 1) {
2300 // If a single character was inserted, then we just send it as a keypress 2311 // If a single character was inserted, then we just send it as a keypress
2301 // event. 2312 // event.
2302 event.SetType(blink::WebInputEvent::kChar); 2313 event.SetType(blink::WebInputEvent::kChar);
2303 event.text[0] = textToBeInserted_[0]; 2314 event.text[0] = textToBeInserted_[0];
2304 event.text[1] = 0; 2315 event.text[1] = 0;
2305 event.skip_in_browser = true; 2316 event.skip_in_browser = true;
2306 widgetHost->ForwardKeyboardEvent(event); 2317 widgetHost->ForwardKeyboardEventWithLatencyInfo(event, latency_info);
2307 } else if ((!textInserted || delayEventUntilAfterImeCompostion) && 2318 } else if ((!textInserted || delayEventUntilAfterImeCompostion) &&
2308 event.text[0] != '\0' && 2319 event.text[0] != '\0' &&
2309 (([theEvent modifierFlags] & kCtrlCmdKeyMask) || 2320 (([theEvent modifierFlags] & kCtrlCmdKeyMask) ||
2310 (hasEditCommands_ && editCommands_.empty()))) { 2321 (hasEditCommands_ && editCommands_.empty()))) {
2311 // We don't get insertText: calls if ctrl or cmd is down, or the key event 2322 // We don't get insertText: calls if ctrl or cmd is down, or the key event
2312 // generates an insert command. So synthesize a keypress event for these 2323 // generates an insert command. So synthesize a keypress event for these
2313 // cases, unless the key event generated any other command. 2324 // cases, unless the key event generated any other command.
2314 event.SetType(blink::WebInputEvent::kChar); 2325 event.SetType(blink::WebInputEvent::kChar);
2315 event.skip_in_browser = true; 2326 event.skip_in_browser = true;
2316 widgetHost->ForwardKeyboardEvent(event); 2327 widgetHost->ForwardKeyboardEventWithLatencyInfo(event, latency_info);
2317 } 2328 }
2318 } 2329 }
2319 2330
2320 // Possibly autohide the cursor. 2331 // Possibly autohide the cursor.
2321 if ([self shouldAutohideCursorForEvent:theEvent]) 2332 if ([self shouldAutohideCursorForEvent:theEvent])
2322 [NSCursor setHiddenUntilMouseMoves:YES]; 2333 [NSCursor setHiddenUntilMouseMoves:YES];
2323 } 2334 }
2324 2335
2325 - (void)forceTouchEvent:(NSEvent*)theEvent { 2336 - (void)forceTouchEvent:(NSEvent*)theEvent {
2326 if (ui::ForceClickInvokesQuickLook()) 2337 if (ui::ForceClickInvokesQuickLook())
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3506 3517
3507 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3518 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3508 // regions that are not draggable. (See ControlRegionView in 3519 // regions that are not draggable. (See ControlRegionView in
3509 // native_app_window_cocoa.mm). This requires the render host view to be 3520 // native_app_window_cocoa.mm). This requires the render host view to be
3510 // draggable by default. 3521 // draggable by default.
3511 - (BOOL)mouseDownCanMoveWindow { 3522 - (BOOL)mouseDownCanMoveWindow {
3512 return YES; 3523 return YES;
3513 } 3524 }
3514 3525
3515 @end 3526 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_event_handler.cc ('k') | content/public/browser/render_widget_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698