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 "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 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 return; | 2091 return; |
2092 } | 2092 } |
2093 | 2093 |
2094 // Don't cancel child popups; the key events are probably what's triggering | 2094 // Don't cancel child popups; the key events are probably what's triggering |
2095 // the popup in the first place. | 2095 // the popup in the first place. |
2096 | 2096 |
2097 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; | 2097 RenderWidgetHostImpl* widgetHost = renderWidgetHostView_->render_widget_host_; |
2098 DCHECK(widgetHost); | 2098 DCHECK(widgetHost); |
2099 | 2099 |
2100 NativeWebKeyboardEvent event(theEvent); | 2100 NativeWebKeyboardEvent event(theEvent); |
| 2101 ui::LatencyInfo latency_info(ui::SourceEventType::KEY); |
| 2102 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
2101 | 2103 |
2102 // Force fullscreen windows to close on Escape so they won't keep the keyboard | 2104 // Force fullscreen windows to close on Escape so they won't keep the keyboard |
2103 // grabbed or be stuck onscreen if the renderer is hanging. | 2105 // grabbed or be stuck onscreen if the renderer is hanging. |
2104 if (event.type() == NativeWebKeyboardEvent::RawKeyDown && | 2106 if (event.type() == NativeWebKeyboardEvent::RawKeyDown && |
2105 event.windowsKeyCode == ui::VKEY_ESCAPE && | 2107 event.windowsKeyCode == ui::VKEY_ESCAPE && |
2106 renderWidgetHostView_->pepper_fullscreen_window()) { | 2108 renderWidgetHostView_->pepper_fullscreen_window()) { |
2107 RenderWidgetHostViewMac* parent = | 2109 RenderWidgetHostViewMac* parent = |
2108 renderWidgetHostView_->fullscreen_parent_host_view(); | 2110 renderWidgetHostView_->fullscreen_parent_host_view(); |
2109 if (parent) | 2111 if (parent) |
2110 parent->cocoa_view()->suppressNextEscapeKeyUp_ = YES; | 2112 parent->cocoa_view()->suppressNextEscapeKeyUp_ = YES; |
(...skipping 19 matching lines...) Expand all Loading... |
2130 // otherwise we might get an event from releasing the return key in the | 2132 // otherwise we might get an event from releasing the return key in the |
2131 // omnibox (http://crbug.com/338736). | 2133 // omnibox (http://crbug.com/338736). |
2132 if ([theEvent type] == NSKeyUp) { | 2134 if ([theEvent type] == NSKeyUp) { |
2133 auto numErased = keyDownCodes_.erase([theEvent keyCode]); | 2135 auto numErased = keyDownCodes_.erase([theEvent keyCode]); |
2134 if (numErased < 1) | 2136 if (numErased < 1) |
2135 return; | 2137 return; |
2136 } | 2138 } |
2137 | 2139 |
2138 // We only handle key down events and just simply forward other events. | 2140 // We only handle key down events and just simply forward other events. |
2139 if ([theEvent type] != NSKeyDown) { | 2141 if ([theEvent type] != NSKeyDown) { |
2140 widgetHost->ForwardKeyboardEvent(event); | 2142 widgetHost->ForwardKeyboardEventWithLatencyInfo(event, latency_info); |
2141 | 2143 |
2142 // Possibly autohide the cursor. | 2144 // Possibly autohide the cursor. |
2143 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 2145 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
2144 [NSCursor setHiddenUntilMouseMoves:YES]; | 2146 [NSCursor setHiddenUntilMouseMoves:YES]; |
2145 | 2147 |
2146 return; | 2148 return; |
2147 } | 2149 } |
2148 | 2150 |
2149 keyDownCodes_.insert([theEvent keyCode]); | 2151 keyDownCodes_.insert([theEvent keyCode]); |
2150 | 2152 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2185 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY | 2187 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY |
2186 // while an input method is composing or inserting a text. | 2188 // while an input method is composing or inserting a text. |
2187 // Gmail checks this code in its onkeydown handler to stop auto-completing | 2189 // Gmail checks this code in its onkeydown handler to stop auto-completing |
2188 // e-mail addresses while composing a CJK text. | 2190 // e-mail addresses while composing a CJK text. |
2189 // If the text to be inserted has only one character, then we don't need this | 2191 // If the text to be inserted has only one character, then we don't need this |
2190 // trick, because we'll send the text as a key press event instead. | 2192 // trick, because we'll send the text as a key press event instead. |
2191 if (hasMarkedText_ || oldHasMarkedText || textToBeInserted_.length() > 1) { | 2193 if (hasMarkedText_ || oldHasMarkedText || textToBeInserted_.length() > 1) { |
2192 NativeWebKeyboardEvent fakeEvent = event; | 2194 NativeWebKeyboardEvent fakeEvent = event; |
2193 fakeEvent.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY | 2195 fakeEvent.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY |
2194 fakeEvent.skip_in_browser = true; | 2196 fakeEvent.skip_in_browser = true; |
2195 widgetHost->ForwardKeyboardEvent(fakeEvent); | 2197 widgetHost->ForwardKeyboardEventWithLatencyInfo(fakeEvent, latency_info); |
2196 // If this key event was handled by the input method, but | 2198 // If this key event was handled by the input method, but |
2197 // -doCommandBySelector: (invoked by the call to -interpretKeyEvents: above) | 2199 // -doCommandBySelector: (invoked by the call to -interpretKeyEvents: above) |
2198 // enqueued edit commands, then in order to let webkit handle them | 2200 // enqueued edit commands, then in order to let webkit handle them |
2199 // correctly, we need to send the real key event and corresponding edit | 2201 // correctly, we need to send the real key event and corresponding edit |
2200 // commands after processing the input method result. | 2202 // commands after processing the input method result. |
2201 // We shouldn't do this if a new marked text was set by the input method, | 2203 // We shouldn't do this if a new marked text was set by the input method, |
2202 // otherwise the new marked text might be cancelled by webkit. | 2204 // otherwise the new marked text might be cancelled by webkit. |
2203 if (hasEditCommands_ && !hasMarkedText_) | 2205 if (hasEditCommands_ && !hasMarkedText_) |
2204 delayEventUntilAfterImeCompostion = YES; | 2206 delayEventUntilAfterImeCompostion = YES; |
2205 } else { | 2207 } else { |
2206 widgetHost->ForwardKeyboardEventWithCommands(event, &editCommands_); | 2208 widgetHost->ForwardKeyboardEventWithCommands(event, latency_info, |
| 2209 &editCommands_); |
2207 } | 2210 } |
2208 | 2211 |
2209 // Calling ForwardKeyboardEvent() could have destroyed the widget. When the | 2212 // Calling ForwardKeyboardEventWithCommands() could have destroyed the |
2210 // widget was destroyed, |renderWidgetHostView_->render_widget_host_| will | 2213 // widget. When the widget was destroyed, |
2211 // be set to NULL. So we check it here and return immediately if it's NULL. | 2214 // |renderWidgetHostView_->render_widget_host_| will be set to NULL. So we |
| 2215 // check it here and return immediately if it's NULL. |
2212 if (!renderWidgetHostView_->render_widget_host_) | 2216 if (!renderWidgetHostView_->render_widget_host_) |
2213 return; | 2217 return; |
2214 | 2218 |
2215 // Then send keypress and/or composition related events. | 2219 // Then send keypress and/or composition related events. |
2216 // If there was a marked text or the text to be inserted is longer than 1 | 2220 // If there was a marked text or the text to be inserted is longer than 1 |
2217 // character, then we send the text by calling FinishComposingText(). | 2221 // character, then we send the text by calling FinishComposingText(). |
2218 // Otherwise, if the text to be inserted only contains 1 character, then we | 2222 // Otherwise, if the text to be inserted only contains 1 character, then we |
2219 // can just send a keypress event which is fabricated by changing the type of | 2223 // can just send a keypress event which is fabricated by changing the type of |
2220 // the keydown event, so that we can retain all necessary informations, such | 2224 // the keydown event, so that we can retain all necessary informations, such |
2221 // as unmodifiedText, etc. And we need to set event.skip_in_browser to true to | 2225 // 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 Loading... |
2260 // finish current composition session but still wants the application to | 2264 // finish current composition session but still wants the application to |
2261 // handle the key event. See http://crbug.com/48161 for reference. | 2265 // handle the key event. See http://crbug.com/48161 for reference. |
2262 if (delayEventUntilAfterImeCompostion) { | 2266 if (delayEventUntilAfterImeCompostion) { |
2263 // If |delayEventUntilAfterImeCompostion| is YES, then a fake key down event | 2267 // If |delayEventUntilAfterImeCompostion| is YES, then a fake key down event |
2264 // with windowsKeyCode == 0xE5 has already been sent to webkit. | 2268 // with windowsKeyCode == 0xE5 has already been sent to webkit. |
2265 // So before sending the real key down event, we need to send a fake key up | 2269 // So before sending the real key down event, we need to send a fake key up |
2266 // event to balance it. | 2270 // event to balance it. |
2267 NativeWebKeyboardEvent fakeEvent = event; | 2271 NativeWebKeyboardEvent fakeEvent = event; |
2268 fakeEvent.setType(blink::WebInputEvent::KeyUp); | 2272 fakeEvent.setType(blink::WebInputEvent::KeyUp); |
2269 fakeEvent.skip_in_browser = true; | 2273 fakeEvent.skip_in_browser = true; |
2270 widgetHost->ForwardKeyboardEvent(fakeEvent); | 2274 widgetHost->ForwardKeyboardEventWithLatencyInfo(fakeEvent, latency_info); |
2271 // Not checking |renderWidgetHostView_->render_widget_host_| here because | 2275 // Not checking |renderWidgetHostView_->render_widget_host_| here because |
2272 // a key event with |skip_in_browser| == true won't be handled by browser, | 2276 // a key event with |skip_in_browser| == true won't be handled by browser, |
2273 // thus it won't destroy the widget. | 2277 // thus it won't destroy the widget. |
2274 | 2278 |
2275 widgetHost->ForwardKeyboardEventWithCommands(event, &editCommands_); | 2279 widgetHost->ForwardKeyboardEventWithCommands(event, latency_info, |
| 2280 &editCommands_); |
2276 | 2281 |
2277 // Calling ForwardKeyboardEvent() could have destroyed the widget. When the | 2282 // Calling ForwardKeyboardEventWithCommands() could have destroyed the |
2278 // widget was destroyed, |renderWidgetHostView_->render_widget_host_| will | 2283 // widget. When the widget was destroyed, |
2279 // be set to NULL. So we check it here and return immediately if it's NULL. | 2284 // |renderWidgetHostView_->render_widget_host_| will be set to NULL. So we |
| 2285 // check it here and return immediately if it's NULL. |
2280 if (!renderWidgetHostView_->render_widget_host_) | 2286 if (!renderWidgetHostView_->render_widget_host_) |
2281 return; | 2287 return; |
2282 } | 2288 } |
2283 | 2289 |
2284 const NSUInteger kCtrlCmdKeyMask = NSControlKeyMask | NSCommandKeyMask; | 2290 const NSUInteger kCtrlCmdKeyMask = NSControlKeyMask | NSCommandKeyMask; |
2285 // Only send a corresponding key press event if there is no marked text. | 2291 // Only send a corresponding key press event if there is no marked text. |
2286 if (!hasMarkedText_) { | 2292 if (!hasMarkedText_) { |
2287 if (!textInserted && textToBeInserted_.length() == 1) { | 2293 if (!textInserted && textToBeInserted_.length() == 1) { |
2288 // If a single character was inserted, then we just send it as a keypress | 2294 // If a single character was inserted, then we just send it as a keypress |
2289 // event. | 2295 // event. |
2290 event.setType(blink::WebInputEvent::Char); | 2296 event.setType(blink::WebInputEvent::Char); |
2291 event.text[0] = textToBeInserted_[0]; | 2297 event.text[0] = textToBeInserted_[0]; |
2292 event.text[1] = 0; | 2298 event.text[1] = 0; |
2293 event.skip_in_browser = true; | 2299 event.skip_in_browser = true; |
2294 widgetHost->ForwardKeyboardEvent(event); | 2300 widgetHost->ForwardKeyboardEventWithLatencyInfo(event, latency_info); |
2295 } else if ((!textInserted || delayEventUntilAfterImeCompostion) && | 2301 } else if ((!textInserted || delayEventUntilAfterImeCompostion) && |
2296 event.text[0] != '\0' && | 2302 event.text[0] != '\0' && |
2297 (([theEvent modifierFlags] & kCtrlCmdKeyMask) || | 2303 (([theEvent modifierFlags] & kCtrlCmdKeyMask) || |
2298 (hasEditCommands_ && editCommands_.empty()))) { | 2304 (hasEditCommands_ && editCommands_.empty()))) { |
2299 // We don't get insertText: calls if ctrl or cmd is down, or the key event | 2305 // We don't get insertText: calls if ctrl or cmd is down, or the key event |
2300 // generates an insert command. So synthesize a keypress event for these | 2306 // generates an insert command. So synthesize a keypress event for these |
2301 // cases, unless the key event generated any other command. | 2307 // cases, unless the key event generated any other command. |
2302 event.setType(blink::WebInputEvent::Char); | 2308 event.setType(blink::WebInputEvent::Char); |
2303 event.skip_in_browser = true; | 2309 event.skip_in_browser = true; |
2304 widgetHost->ForwardKeyboardEvent(event); | 2310 widgetHost->ForwardKeyboardEventWithLatencyInfo(event, latency_info); |
2305 } | 2311 } |
2306 } | 2312 } |
2307 | 2313 |
2308 // Possibly autohide the cursor. | 2314 // Possibly autohide the cursor. |
2309 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 2315 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
2310 [NSCursor setHiddenUntilMouseMoves:YES]; | 2316 [NSCursor setHiddenUntilMouseMoves:YES]; |
2311 } | 2317 } |
2312 | 2318 |
2313 - (void)forceTouchEvent:(NSEvent*)theEvent { | 2319 - (void)forceTouchEvent:(NSEvent*)theEvent { |
2314 if (ui::ForceClickInvokesQuickLook()) | 2320 if (ui::ForceClickInvokesQuickLook()) |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3507 | 3513 |
3508 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3514 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3509 // regions that are not draggable. (See ControlRegionView in | 3515 // regions that are not draggable. (See ControlRegionView in |
3510 // native_app_window_cocoa.mm). This requires the render host view to be | 3516 // native_app_window_cocoa.mm). This requires the render host view to be |
3511 // draggable by default. | 3517 // draggable by default. |
3512 - (BOOL)mouseDownCanMoveWindow { | 3518 - (BOOL)mouseDownCanMoveWindow { |
3513 return YES; | 3519 return YES; |
3514 } | 3520 } |
3515 | 3521 |
3516 @end | 3522 @end |
OLD | NEW |