| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "sky/engine/core/page/Chrome.h" | 57 #include "sky/engine/core/page/Chrome.h" |
| 58 #include "sky/engine/core/page/EventHandler.h" | 58 #include "sky/engine/core/page/EventHandler.h" |
| 59 #include "sky/engine/core/page/EventWithHitTestResults.h" | 59 #include "sky/engine/core/page/EventWithHitTestResults.h" |
| 60 #include "sky/engine/core/page/FocusController.h" | 60 #include "sky/engine/core/page/FocusController.h" |
| 61 #include "sky/engine/core/page/Page.h" | 61 #include "sky/engine/core/page/Page.h" |
| 62 #include "sky/engine/core/rendering/RenderView.h" | 62 #include "sky/engine/core/rendering/RenderView.h" |
| 63 #include "sky/engine/platform/Cursor.h" | 63 #include "sky/engine/platform/Cursor.h" |
| 64 #include "sky/engine/platform/KeyboardCodes.h" | 64 #include "sky/engine/platform/KeyboardCodes.h" |
| 65 #include "sky/engine/platform/Logging.h" | 65 #include "sky/engine/platform/Logging.h" |
| 66 #include "sky/engine/platform/NotImplemented.h" | 66 #include "sky/engine/platform/NotImplemented.h" |
| 67 #include "sky/engine/platform/PlatformKeyboardEvent.h" | |
| 68 #include "sky/engine/platform/TraceEvent.h" | 67 #include "sky/engine/platform/TraceEvent.h" |
| 69 #include "sky/engine/platform/fonts/FontCache.h" | 68 #include "sky/engine/platform/fonts/FontCache.h" |
| 70 #include "sky/engine/platform/graphics/Color.h" | 69 #include "sky/engine/platform/graphics/Color.h" |
| 71 #include "sky/engine/platform/graphics/GraphicsContext.h" | 70 #include "sky/engine/platform/graphics/GraphicsContext.h" |
| 72 #include "sky/engine/platform/graphics/Image.h" | 71 #include "sky/engine/platform/graphics/Image.h" |
| 73 #include "sky/engine/platform/graphics/ImageBuffer.h" | 72 #include "sky/engine/platform/graphics/ImageBuffer.h" |
| 74 #include "sky/engine/platform/scroll/Scrollbar.h" | 73 #include "sky/engine/platform/scroll/Scrollbar.h" |
| 75 #include "sky/engine/public/platform/Platform.h" | 74 #include "sky/engine/public/platform/Platform.h" |
| 76 #include "sky/engine/public/platform/WebFloatPoint.h" | 75 #include "sky/engine/public/platform/WebFloatPoint.h" |
| 77 #include "sky/engine/public/platform/WebImage.h" | 76 #include "sky/engine/public/platform/WebImage.h" |
| 78 #include "sky/engine/public/platform/WebLayerTreeView.h" | 77 #include "sky/engine/public/platform/WebLayerTreeView.h" |
| 79 #include "sky/engine/public/platform/WebURLRequest.h" | 78 #include "sky/engine/public/platform/WebURLRequest.h" |
| 80 #include "sky/engine/public/platform/WebVector.h" | 79 #include "sky/engine/public/platform/WebVector.h" |
| 81 #include "sky/engine/public/web/WebBeginFrameArgs.h" | 80 #include "sky/engine/public/web/WebBeginFrameArgs.h" |
| 82 #include "sky/engine/public/web/WebFrameClient.h" | 81 #include "sky/engine/public/web/WebFrameClient.h" |
| 83 #include "sky/engine/public/web/WebHitTestResult.h" | 82 #include "sky/engine/public/web/WebHitTestResult.h" |
| 84 #include "sky/engine/public/web/WebNode.h" | 83 #include "sky/engine/public/web/WebNode.h" |
| 85 #include "sky/engine/public/web/WebRange.h" | 84 #include "sky/engine/public/web/WebRange.h" |
| 86 #include "sky/engine/public/web/WebTextInputInfo.h" | 85 #include "sky/engine/public/web/WebTextInputInfo.h" |
| 87 #include "sky/engine/public/web/WebViewClient.h" | 86 #include "sky/engine/public/web/WebViewClient.h" |
| 88 #include "sky/engine/web/CompositionUnderlineVectorBuilder.h" | 87 #include "sky/engine/web/CompositionUnderlineVectorBuilder.h" |
| 89 #include "sky/engine/web/WebInputEventConversion.h" | |
| 90 #include "sky/engine/web/WebLocalFrameImpl.h" | 88 #include "sky/engine/web/WebLocalFrameImpl.h" |
| 91 #include "sky/engine/web/WebSettingsImpl.h" | 89 #include "sky/engine/web/WebSettingsImpl.h" |
| 92 #include "sky/engine/wtf/CurrentTime.h" | 90 #include "sky/engine/wtf/CurrentTime.h" |
| 93 #include "sky/engine/wtf/RefPtr.h" | 91 #include "sky/engine/wtf/RefPtr.h" |
| 94 #include "sky/engine/wtf/TemporaryChange.h" | 92 #include "sky/engine/wtf/TemporaryChange.h" |
| 95 | 93 |
| 96 // Get rid of WTF's pow define so we can use std::pow. | 94 // Get rid of WTF's pow define so we can use std::pow. |
| 97 #undef pow | 95 #undef pow |
| 98 #include <cmath> // for std::pow | 96 #include <cmath> // for std::pow |
| 99 | 97 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 182 } |
| 185 | 183 |
| 186 void WebViewImpl::acceptLanguagesChanged() | 184 void WebViewImpl::acceptLanguagesChanged() |
| 187 { | 185 { |
| 188 if (!page()) | 186 if (!page()) |
| 189 return; | 187 return; |
| 190 | 188 |
| 191 page()->acceptLanguagesChanged(); | 189 page()->acceptLanguagesChanged(); |
| 192 } | 190 } |
| 193 | 191 |
| 194 bool WebViewImpl::handleKeyEvent(const WebKeyboardEvent& event) | |
| 195 { | |
| 196 ASSERT((event.type == WebInputEvent::RawKeyDown) | |
| 197 || (event.type == WebInputEvent::KeyDown) | |
| 198 || (event.type == WebInputEvent::KeyUp)); | |
| 199 | |
| 200 // Please refer to the comments explaining the m_suppressNextKeypressEvent | |
| 201 // member. | |
| 202 // The m_suppressNextKeypressEvent is set if the KeyDown is handled by | |
| 203 // Webkit. A keyDown event is typically associated with a keyPress(char) | |
| 204 // event and a keyUp event. We reset this flag here as this is a new keyDown | |
| 205 // event. | |
| 206 m_suppressNextKeypressEvent = false; | |
| 207 | |
| 208 RefPtr<LocalFrame> focusedFrame = focusedCoreFrame(); | |
| 209 if (!focusedFrame) | |
| 210 return false; | |
| 211 | |
| 212 RefPtr<LocalFrame> frame = focusedFrame.get(); | |
| 213 | |
| 214 PlatformKeyboardEventBuilder evt(event); | |
| 215 | |
| 216 if (frame->eventHandler().keyEvent(evt)) { | |
| 217 if (WebInputEvent::RawKeyDown == event.type) { | |
| 218 // Suppress the next keypress event unless the focused node is a plu
g-in node. | |
| 219 // (Flash needs these keypress events to handle non-US keyboards.) | |
| 220 m_suppressNextKeypressEvent = true; | |
| 221 } | |
| 222 return true; | |
| 223 } | |
| 224 | |
| 225 return keyEventDefault(event); | |
| 226 } | |
| 227 | |
| 228 bool WebViewImpl::handleCharEvent(const WebKeyboardEvent& event) | |
| 229 { | |
| 230 ASSERT(event.type == WebInputEvent::Char); | |
| 231 | |
| 232 // Please refer to the comments explaining the m_suppressNextKeypressEvent | |
| 233 // member. The m_suppressNextKeypressEvent is set if the KeyDown is | |
| 234 // handled by Webkit. A keyDown event is typically associated with a | |
| 235 // keyPress(char) event and a keyUp event. We reset this flag here as it | |
| 236 // only applies to the current keyPress event. | |
| 237 bool suppress = m_suppressNextKeypressEvent; | |
| 238 m_suppressNextKeypressEvent = false; | |
| 239 | |
| 240 LocalFrame* frame = focusedCoreFrame(); | |
| 241 if (!frame) | |
| 242 return suppress; | |
| 243 | |
| 244 EventHandler& handler = frame->eventHandler(); | |
| 245 | |
| 246 PlatformKeyboardEventBuilder evt(event); | |
| 247 if (!evt.isCharacterKey()) | |
| 248 return true; | |
| 249 | |
| 250 // Safari 3.1 does not pass off windows system key messages (WM_SYSCHAR) to | |
| 251 // the eventHandler::keyEvent. We mimic this behavior on all platforms since | |
| 252 // for now we are converting other platform's key events to windows key | |
| 253 // events. | |
| 254 if (evt.isSystemKey()) | |
| 255 return false; | |
| 256 | |
| 257 if (!suppress && !handler.keyEvent(evt)) | |
| 258 return keyEventDefault(event); | |
| 259 | |
| 260 return true; | |
| 261 } | |
| 262 | |
| 263 bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event) | |
| 264 { | |
| 265 LocalFrame* frame = focusedCoreFrame(); | |
| 266 if (!frame) | |
| 267 return false; | |
| 268 | |
| 269 switch (event.type) { | |
| 270 case WebInputEvent::Char: | |
| 271 if (event.windowsKeyCode == VKEY_SPACE) { | |
| 272 int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PR
IOR : VKEY_NEXT); | |
| 273 return scrollViewWithKeyboard(keyCode, event.modifiers); | |
| 274 } | |
| 275 break; | |
| 276 case WebInputEvent::RawKeyDown: | |
| 277 if (event.modifiers == WebInputEvent::ControlKey) { | |
| 278 switch (event.windowsKeyCode) { | |
| 279 // Match FF behavior in the sense that Ctrl+home/end are the only Ct
rl | |
| 280 // key combinations which affect scrolling. Safari is buggy in the | |
| 281 // sense that it scrolls the page for all Ctrl+scrolling key | |
| 282 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc. | |
| 283 case VKEY_HOME: | |
| 284 case VKEY_END: | |
| 285 break; | |
| 286 default: | |
| 287 return false; | |
| 288 } | |
| 289 } | |
| 290 if (!event.isSystemKey && !(event.modifiers & WebInputEvent::ShiftKey)) | |
| 291 return scrollViewWithKeyboard(event.windowsKeyCode, event.modifiers)
; | |
| 292 break; | |
| 293 default: | |
| 294 break; | |
| 295 } | |
| 296 return false; | |
| 297 } | |
| 298 | |
| 299 bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers) | |
| 300 { | |
| 301 ScrollDirection scrollDirection; | |
| 302 ScrollGranularity scrollGranularity; | |
| 303 if (!mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranularity)) | |
| 304 return false; | |
| 305 | |
| 306 if (LocalFrame* frame = focusedCoreFrame()) | |
| 307 return frame->eventHandler().bubblingScroll(scrollDirection, scrollGranu
larity); | |
| 308 return false; | |
| 309 } | |
| 310 | |
| 311 bool WebViewImpl::mapKeyCodeForScroll( | |
| 312 int keyCode, | |
| 313 ScrollDirection* scrollDirection, | |
| 314 ScrollGranularity* scrollGranularity) | |
| 315 { | |
| 316 switch (keyCode) { | |
| 317 case VKEY_LEFT: | |
| 318 *scrollDirection = ScrollLeft; | |
| 319 *scrollGranularity = ScrollByLine; | |
| 320 break; | |
| 321 case VKEY_RIGHT: | |
| 322 *scrollDirection = ScrollRight; | |
| 323 *scrollGranularity = ScrollByLine; | |
| 324 break; | |
| 325 case VKEY_UP: | |
| 326 *scrollDirection = ScrollUp; | |
| 327 *scrollGranularity = ScrollByLine; | |
| 328 break; | |
| 329 case VKEY_DOWN: | |
| 330 *scrollDirection = ScrollDown; | |
| 331 *scrollGranularity = ScrollByLine; | |
| 332 break; | |
| 333 case VKEY_HOME: | |
| 334 *scrollDirection = ScrollUp; | |
| 335 *scrollGranularity = ScrollByDocument; | |
| 336 break; | |
| 337 case VKEY_END: | |
| 338 *scrollDirection = ScrollDown; | |
| 339 *scrollGranularity = ScrollByDocument; | |
| 340 break; | |
| 341 case VKEY_PRIOR: // page up | |
| 342 *scrollDirection = ScrollUp; | |
| 343 *scrollGranularity = ScrollByPage; | |
| 344 break; | |
| 345 case VKEY_NEXT: // page down | |
| 346 *scrollDirection = ScrollDown; | |
| 347 *scrollGranularity = ScrollByPage; | |
| 348 break; | |
| 349 default: | |
| 350 return false; | |
| 351 } | |
| 352 | |
| 353 return true; | |
| 354 } | |
| 355 | |
| 356 LocalFrame* WebViewImpl::focusedCoreFrame() const | 192 LocalFrame* WebViewImpl::focusedCoreFrame() const |
| 357 { | 193 { |
| 358 return m_page ? m_page->focusController().focusedOrMainFrame() : 0; | 194 return m_page ? m_page->focusController().focusedOrMainFrame() : 0; |
| 359 } | 195 } |
| 360 | 196 |
| 361 WebViewImpl* WebViewImpl::fromPage(Page* page) | 197 WebViewImpl* WebViewImpl::fromPage(Page* page) |
| 362 { | 198 { |
| 363 if (!page) | 199 if (!page) |
| 364 return 0; | 200 return 0; |
| 365 return static_cast<WebViewImpl*>(page->chrome().client().webView()); | 201 return static_cast<WebViewImpl*>(page->chrome().client().webView()); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 if (WebInputEvent::isPointerEventType(inputEvent.type)) { | 330 if (WebInputEvent::isPointerEventType(inputEvent.type)) { |
| 495 const WebPointerEvent& event = static_cast<const WebPointerEvent&>(input
Event); | 331 const WebPointerEvent& event = static_cast<const WebPointerEvent&>(input
Event); |
| 496 return m_page->mainFrame()->newEventHandler().handlePointerEvent(event); | 332 return m_page->mainFrame()->newEventHandler().handlePointerEvent(event); |
| 497 } | 333 } |
| 498 | 334 |
| 499 if (WebInputEvent::isGestureEventType(inputEvent.type)) { | 335 if (WebInputEvent::isGestureEventType(inputEvent.type)) { |
| 500 const WebGestureEvent& event = static_cast<const WebGestureEvent&>(input
Event); | 336 const WebGestureEvent& event = static_cast<const WebGestureEvent&>(input
Event); |
| 501 return m_page->mainFrame()->newEventHandler().handleGestureEvent(event); | 337 return m_page->mainFrame()->newEventHandler().handleGestureEvent(event); |
| 502 } | 338 } |
| 503 | 339 |
| 504 switch (inputEvent.type) { | 340 if (WebInputEvent::isKeyboardEventType(inputEvent.type)) { |
| 505 case WebInputEvent::RawKeyDown: | 341 const WebKeyboardEvent& event = static_cast<const WebKeyboardEvent&>(inp
utEvent); |
| 506 case WebInputEvent::KeyDown: | 342 return m_page->mainFrame()->newEventHandler().handleKeyboardEvent(event)
; |
| 507 case WebInputEvent::KeyUp: | |
| 508 return handleKeyEvent(static_cast<const WebKeyboardEvent&>(inputEvent)); | |
| 509 case WebInputEvent::Char: | |
| 510 return handleCharEvent(static_cast<const WebKeyboardEvent&>(inputEvent))
; | |
| 511 default: | |
| 512 return false; | |
| 513 } | 343 } |
| 344 |
| 345 return false; |
| 514 } | 346 } |
| 515 | 347 |
| 516 void WebViewImpl::setFocus(bool enable) | 348 void WebViewImpl::setFocus(bool enable) |
| 517 { | 349 { |
| 518 m_page->focusController().setFocused(enable); | 350 m_page->focusController().setFocused(enable); |
| 519 if (enable) { | 351 if (enable) { |
| 520 m_page->focusController().setActive(true); | 352 m_page->focusController().setActive(true); |
| 521 RefPtr<LocalFrame> focusedFrame = m_page->focusController().focusedFrame
(); | 353 RefPtr<LocalFrame> focusedFrame = m_page->focusController().focusedFrame
(); |
| 522 if (focusedFrame) { | 354 if (focusedFrame) { |
| 523 LocalFrame* localFrame = focusedFrame.get(); | 355 LocalFrame* localFrame = focusedFrame.get(); |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState, | 899 void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState, |
| 1068 bool isInitialState) { | 900 bool isInitialState) { |
| 1069 if (!page()) | 901 if (!page()) |
| 1070 return; | 902 return; |
| 1071 | 903 |
| 1072 ASSERT(visibilityState == WebPageVisibilityStateVisible || visibilityState =
= WebPageVisibilityStateHidden); | 904 ASSERT(visibilityState == WebPageVisibilityStateVisible || visibilityState =
= WebPageVisibilityStateHidden); |
| 1073 m_page->setVisibilityState(static_cast<PageVisibilityState>(static_cast<int>
(visibilityState)), isInitialState); | 905 m_page->setVisibilityState(static_cast<PageVisibilityState>(static_cast<int>
(visibilityState)), isInitialState); |
| 1074 } | 906 } |
| 1075 | 907 |
| 1076 } // namespace blink | 908 } // namespace blink |
| OLD | NEW |