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

Side by Side Diff: Source/web/WebViewImpl.cpp

Issue 939603002: Adding support for Smart GO NEXT feature in Android Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Corrected the eventlistener identification till topmost element. Created 5 years, 8 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
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | public/web/WebTextInputType.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "web/WebViewImpl.h" 32 #include "web/WebViewImpl.h"
33 33
34 #include "core/CSSValueKeywords.h" 34 #include "core/CSSValueKeywords.h"
35 #include "core/HTMLNames.h" 35 #include "core/HTMLNames.h"
36 #include "core/InputTypeNames.h" 36 #include "core/InputTypeNames.h"
37 #include "core/clipboard/DataObject.h" 37 #include "core/clipboard/DataObject.h"
38 #include "core/dom/Document.h" 38 #include "core/dom/Document.h"
39 #include "core/dom/DocumentMarkerController.h" 39 #include "core/dom/DocumentMarkerController.h"
40 #include "core/dom/ElementTraversal.h"
40 #include "core/dom/Fullscreen.h" 41 #include "core/dom/Fullscreen.h"
41 #include "core/dom/LayoutTreeBuilderTraversal.h" 42 #include "core/dom/LayoutTreeBuilderTraversal.h"
42 #include "core/dom/Text.h" 43 #include "core/dom/Text.h"
43 #include "core/editing/Editor.h" 44 #include "core/editing/Editor.h"
44 #include "core/editing/FrameSelection.h" 45 #include "core/editing/FrameSelection.h"
45 #include "core/editing/HTMLInterchange.h" 46 #include "core/editing/HTMLInterchange.h"
46 #include "core/editing/InputMethodController.h" 47 #include "core/editing/InputMethodController.h"
47 #include "core/editing/iterators/TextIterator.h" 48 #include "core/editing/iterators/TextIterator.h"
48 #include "core/editing/markup.h" 49 #include "core/editing/markup.h"
49 #include "core/events/KeyboardEvent.h" 50 #include "core/events/KeyboardEvent.h"
50 #include "core/events/UIEventWithKeyState.h" 51 #include "core/events/UIEventWithKeyState.h"
51 #include "core/events/WheelEvent.h" 52 #include "core/events/WheelEvent.h"
52 #include "core/fetch/UniqueIdentifier.h" 53 #include "core/fetch/UniqueIdentifier.h"
53 #include "core/frame/EventHandlerRegistry.h" 54 #include "core/frame/EventHandlerRegistry.h"
54 #include "core/frame/FrameHost.h" 55 #include "core/frame/FrameHost.h"
55 #include "core/frame/FrameView.h" 56 #include "core/frame/FrameView.h"
56 #include "core/frame/LocalFrame.h" 57 #include "core/frame/LocalFrame.h"
57 #include "core/frame/PinchViewport.h" 58 #include "core/frame/PinchViewport.h"
58 #include "core/frame/RemoteFrame.h" 59 #include "core/frame/RemoteFrame.h"
59 #include "core/frame/Settings.h" 60 #include "core/frame/Settings.h"
60 #include "core/frame/SmartClip.h" 61 #include "core/frame/SmartClip.h"
61 #include "core/frame/TopControls.h" 62 #include "core/frame/TopControls.h"
63 #include "core/html/HTMLFormElement.h"
62 #include "core/html/HTMLInputElement.h" 64 #include "core/html/HTMLInputElement.h"
63 #include "core/html/HTMLMediaElement.h" 65 #include "core/html/HTMLMediaElement.h"
64 #include "core/html/HTMLPlugInElement.h" 66 #include "core/html/HTMLPlugInElement.h"
65 #include "core/html/HTMLTextAreaElement.h" 67 #include "core/html/HTMLTextAreaElement.h"
66 #include "core/html/canvas/WebGLRenderingContext.h" 68 #include "core/html/canvas/WebGLRenderingContext.h"
67 #include "core/html/forms/PopupMenuClient.h" 69 #include "core/html/forms/PopupMenuClient.h"
68 #include "core/html/ime/InputMethodContext.h" 70 #include "core/html/ime/InputMethodContext.h"
69 #include "core/layout/LayoutPart.h" 71 #include "core/layout/LayoutPart.h"
70 #include "core/layout/LayoutView.h" 72 #include "core/layout/LayoutView.h"
71 #include "core/layout/TextAutosizer.h" 73 #include "core/layout/TextAutosizer.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 #include "platform/graphics/Color.h" 111 #include "platform/graphics/Color.h"
110 #include "platform/graphics/FirstPaintInvalidationTracking.h" 112 #include "platform/graphics/FirstPaintInvalidationTracking.h"
111 #include "platform/graphics/Image.h" 113 #include "platform/graphics/Image.h"
112 #include "platform/graphics/ImageBuffer.h" 114 #include "platform/graphics/ImageBuffer.h"
113 #include "platform/scroll/ScrollbarTheme.h" 115 #include "platform/scroll/ScrollbarTheme.h"
114 #include "platform/weborigin/SchemeRegistry.h" 116 #include "platform/weborigin/SchemeRegistry.h"
115 #include "public/platform/Platform.h" 117 #include "public/platform/Platform.h"
116 #include "public/platform/WebCompositeAndReadbackAsyncCallback.h" 118 #include "public/platform/WebCompositeAndReadbackAsyncCallback.h"
117 #include "public/platform/WebDragData.h" 119 #include "public/platform/WebDragData.h"
118 #include "public/platform/WebFloatPoint.h" 120 #include "public/platform/WebFloatPoint.h"
121 #include "public/platform/WebFocusType.h"
119 #include "public/platform/WebGestureCurve.h" 122 #include "public/platform/WebGestureCurve.h"
120 #include "public/platform/WebImage.h" 123 #include "public/platform/WebImage.h"
121 #include "public/platform/WebLayerTreeView.h" 124 #include "public/platform/WebLayerTreeView.h"
122 #include "public/platform/WebURLRequest.h" 125 #include "public/platform/WebURLRequest.h"
123 #include "public/platform/WebVector.h" 126 #include "public/platform/WebVector.h"
124 #include "public/web/WebAXObject.h" 127 #include "public/web/WebAXObject.h"
125 #include "public/web/WebActiveWheelFlingParameters.h" 128 #include "public/web/WebActiveWheelFlingParameters.h"
126 #include "public/web/WebAutofillClient.h" 129 #include "public/web/WebAutofillClient.h"
127 #include "public/web/WebBeginFrameArgs.h" 130 #include "public/web/WebBeginFrameArgs.h"
128 #include "public/web/WebFrameClient.h" 131 #include "public/web/WebFrameClient.h"
(...skipping 2380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 flags |= WebTextInputFlagAutocapitalizeCharacters; 2512 flags |= WebTextInputFlagAutocapitalizeCharacters;
2510 else if (autocapitalize == words) 2513 else if (autocapitalize == words)
2511 flags |= WebTextInputFlagAutocapitalizeWords; 2514 flags |= WebTextInputFlagAutocapitalizeWords;
2512 else if (autocapitalize == sentences) 2515 else if (autocapitalize == sentences)
2513 flags |= WebTextInputFlagAutocapitalizeSentences; 2516 flags |= WebTextInputFlagAutocapitalizeSentences;
2514 else 2517 else
2515 ASSERT_NOT_REACHED(); 2518 ASSERT_NOT_REACHED();
2516 } 2519 }
2517 } 2520 }
2518 2521
2522 if (isListeningToKeyboardEvents(element))
2523 flags |= WebTextInputFlagListeningToKeyboardEvents;
2524
2525 if (nextFocusableElementInForm(element, WebFocusTypeForward))
2526 flags |= WebTextInputFlagHaveNextFocusableElement;
2527
2528 if (nextFocusableElementInForm(element, WebFocusTypeBackward))
2529 flags |= WebTextInputFlagHavePreviousFocusableElement;
2530
2519 return flags; 2531 return flags;
2520 } 2532 }
2521 2533
2534 Element* WebViewImpl::nextFocusableElementInForm(Element* element, WebFocusType focusType)
2535 {
2536 if (!element->isFormControlElement() && !element->isContentEditable())
2537 return nullptr;
2538
2539 HTMLFormElement* formOwner = nullptr;
2540 if (element->isContentEditable())
2541 formOwner = Traversal<HTMLFormElement>::firstAncestor(*element);
2542 else
2543 formOwner = toHTMLFormControlElement(element)->formOwner();
2544
2545 if (!formOwner)
2546 return nullptr;
2547
2548 Node* nextNode = element;
2549 while ((nextNode = page()->focusController().findFocusableNode(focusType, *n extNode))) {
2550 if (nextNode->isContentEditable() && nextNode->isDescendantOf(formOwner) )
2551 return toElement(nextNode);
2552 if (!toElement(nextNode)->isFormControlElement())
2553 continue;
2554 HTMLFormControlElement* formElement = toHTMLFormControlElement(nextNode) ;
2555 if (formElement->formOwner() != formOwner)
2556 continue;
2557 LayoutObject* layout = nextNode->layoutObject();
2558 if (layout && layout->isTextControl()) {
2559 // TODO(ajith.v) Extend it for Select element, Radio button and Chec k boxes
2560 return toElement(nextNode);
2561 }
2562 }
2563 return nullptr;
2564 }
2565
2566 bool WebViewImpl::isListeningToKeyboardEvents(Element* element)
2567 {
2568 if (!element->isFormControlElement() && !element->isContentEditable())
2569 return false;
2570
2571 bool hasKeyEventListener = element->hasEventListeners(EventTypeNames::keydow n) || element->hasEventListeners(EventTypeNames::keypress) || element->hasEventL isteners(EventTypeNames::keyup);
2572 if (hasKeyEventListener)
2573 return true;
2574
2575 Document& document = element->document();
2576 hasKeyEventListener = document.hasEventListeners(EventTypeNames::keydown) || document.hasEventListeners(EventTypeNames::keypress) || document.hasEventListen ers(EventTypeNames::keyup);
2577 if (hasKeyEventListener)
2578 return true;
2579
2580 HTMLFormElement* formOwner = nullptr;
2581 if (element->isContentEditable())
2582 formOwner = Traversal<HTMLFormElement>::firstAncestor(*element);
2583 else
2584 formOwner = toHTMLFormControlElement(element)->formOwner();
2585
2586 if (!formOwner)
2587 return false;
2588
2589 hasKeyEventListener = formOwner->hasEventListeners(EventTypeNames::keydown) || formOwner->hasEventListeners(EventTypeNames::keypress) || formOwner->hasEvent Listeners(EventTypeNames::keyup);
tkent 2015/04/21 07:41:27 You don't need to check event listeners on the for
AKV 2015/04/21 07:52:59 Thanks. My idea was to return early, rather than t
2590 if (hasKeyEventListener)
2591 return true;
2592
2593 Element* parent = element;
2594 while ((parent = parent->parentElement())) {
tkent 2015/04/21 07:41:27 Node* node = element; do { if (node->hasEventL
AKV 2015/04/21 07:52:59 For returning early purpose, I added Element and D
2595 hasKeyEventListener = parent->hasEventListeners(EventTypeNames::keydown) || parent->hasEventListeners(EventTypeNames::keypress) || parent->hasEventListe ners(EventTypeNames::keyup);
2596 if (hasKeyEventListener)
2597 return true;
2598 }
2599 return hasKeyEventListener;
2600 }
2601
2602 void WebViewImpl::advanceFocusInForm(WebFocusType focusType)
2603 {
2604 Element* element = focusedElement();
2605 if (!element)
2606 return;
2607
2608 RefPtrWillBeRawPtr<Element> nextElement = nextFocusableElementInForm(element , focusType);
2609 if (!nextElement)
2610 return;
2611
2612 nextElement->scrollIntoViewIfNeeded(true /*centerIfNeeded*/);
2613 nextElement->focus(false, focusType);
2614 }
2615
2522 WebString WebViewImpl::inputModeOfFocusedElement() 2616 WebString WebViewImpl::inputModeOfFocusedElement()
2523 { 2617 {
2524 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled()) 2618 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled())
2525 return WebString(); 2619 return WebString();
2526 2620
2527 Element* element = focusedElement(); 2621 Element* element = focusedElement();
2528 if (!element) 2622 if (!element)
2529 return WebString(); 2623 return WebString();
2530 2624
2531 if (isHTMLInputElement(*element)) { 2625 if (isHTMLInputElement(*element)) {
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after
4457 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width 4551 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width
4458 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1); 4552 || (constraints.minimumScale == constraints.maximumScale && constraints. minimumScale != -1);
4459 } 4553 }
4460 4554
4461 void WebViewImpl::forceNextWebGLContextCreationToFail() 4555 void WebViewImpl::forceNextWebGLContextCreationToFail()
4462 { 4556 {
4463 WebGLRenderingContext::forceNextWebGLContextCreationToFail(); 4557 WebGLRenderingContext::forceNextWebGLContextCreationToFail();
4464 } 4558 }
4465 4559
4466 } // namespace blink 4560 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | public/web/WebTextInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698