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

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

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

Powered by Google App Engine
This is Rietveld 408576698