| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/renderer/page_click_tracker.h" | 5 #include "components/autofill/content/renderer/page_click_tracker.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "components/autofill/content/renderer/form_autofill_util.h" | 8 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 9 #include "components/autofill/content/renderer/page_click_listener.h" | 9 #include "components/autofill/content/renderer/page_click_listener.h" |
| 10 #include "components/autofill/core/common/autofill_util.h" | 10 #include "components/autofill/core/common/autofill_util.h" |
| 11 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
| 12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
| 13 #include "third_party/WebKit/public/platform/WebPoint.h" | 13 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 14 #include "third_party/WebKit/public/platform/WebSize.h" | 14 #include "third_party/WebKit/public/platform/WebSize.h" |
| 15 #include "third_party/WebKit/public/web/WebDocument.h" | 15 #include "third_party/WebKit/public/web/WebDocument.h" |
| 16 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 16 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 17 #include "third_party/WebKit/public/web/WebHitTestResult.h" | 17 #include "third_party/WebKit/public/web/WebHitTestResult.h" |
| 18 #include "third_party/WebKit/public/web/WebInputElement.h" | 18 #include "third_party/WebKit/public/web/WebInputElement.h" |
| 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 20 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 20 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 21 #include "third_party/WebKit/public/web/WebView.h" | 21 #include "third_party/WebKit/public/web/WebView.h" |
| 22 | 22 |
| 23 using blink::WebElement; | 23 using blink::WebElement; |
| 24 using blink::WebFormControlElement; | 24 using blink::WebFormControlElement; |
| 25 using blink::WebGestureEvent; | |
| 26 using blink::WebInputElement; | 25 using blink::WebInputElement; |
| 27 using blink::WebNode; | 26 using blink::WebNode; |
| 28 using blink::WebPoint; | 27 using blink::WebPoint; |
| 29 using blink::WebSize; | 28 using blink::WebSize; |
| 30 using blink::WebUserGestureIndicator; | 29 using blink::WebUserGestureIndicator; |
| 31 | 30 |
| 32 namespace autofill { | 31 namespace autofill { |
| 33 | 32 |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 // Casts |element| to a WebFormControlElement, but only if it's a text field. | 35 // Casts |element| to a WebFormControlElement, but only if it's a text field. |
| 37 // Returns an empty (isNull()) wrapper otherwise. | 36 // Returns an empty (IsNull()) wrapper otherwise. |
| 38 const WebFormControlElement GetTextFormControlElement( | 37 const WebFormControlElement GetTextFormControlElement( |
| 39 const WebElement& element) { | 38 const WebElement& element) { |
| 40 if (!element.IsFormControlElement()) | 39 if (!element.IsFormControlElement()) |
| 41 return WebFormControlElement(); | 40 return WebFormControlElement(); |
| 42 if (form_util::IsTextInput(blink::ToWebInputElement(&element)) || | 41 if (form_util::IsTextInput(blink::ToWebInputElement(&element)) || |
| 43 element.HasHTMLTagName("textarea")) | 42 element.HasHTMLTagName("textarea")) |
| 44 return element.ToConst<WebFormControlElement>(); | 43 return element.ToConst<WebFormControlElement>(); |
| 45 return WebFormControlElement(); | 44 return WebFormControlElement(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 PageClickTracker::PageClickTracker(content::RenderFrame* render_frame, | 49 PageClickTracker::PageClickTracker(content::RenderFrame* render_frame, |
| 51 PageClickListener* listener) | 50 PageClickListener* listener) |
| 52 : content::RenderFrameObserver(render_frame), | 51 : focused_node_was_last_clicked_(false), |
| 53 focused_node_was_last_clicked_(false), | |
| 54 was_focused_before_now_(false), | 52 was_focused_before_now_(false), |
| 55 listener_(listener), | 53 listener_(listener), |
| 56 legacy_(this) { | 54 render_frame_(render_frame) {} |
| 57 } | |
| 58 | 55 |
| 59 PageClickTracker::~PageClickTracker() { | 56 PageClickTracker::~PageClickTracker() { |
| 60 } | 57 } |
| 61 | 58 |
| 62 void PageClickTracker::OnMouseDown(const WebNode& mouse_down_node) { | |
| 63 focused_node_was_last_clicked_ = | |
| 64 !mouse_down_node.IsNull() && mouse_down_node.Focused(); | |
| 65 | |
| 66 if (IsKeyboardAccessoryEnabled()) | |
| 67 DoFocusChangeComplete(); | |
| 68 } | |
| 69 | |
| 70 void PageClickTracker::FocusedNodeChanged(const WebNode& node) { | 59 void PageClickTracker::FocusedNodeChanged(const WebNode& node) { |
| 71 was_focused_before_now_ = false; | 60 was_focused_before_now_ = false; |
| 72 | 61 |
| 73 if (IsKeyboardAccessoryEnabled() && | 62 if (IsKeyboardAccessoryEnabled() && |
| 74 WebUserGestureIndicator::IsProcessingUserGesture()) { | 63 WebUserGestureIndicator::IsProcessingUserGesture()) { |
| 75 focused_node_was_last_clicked_ = true; | 64 focused_node_was_last_clicked_ = true; |
| 76 DoFocusChangeComplete(); | 65 DoFocusChangeComplete(); |
| 77 } | 66 } |
| 78 } | 67 } |
| 79 | 68 |
| 80 void PageClickTracker::FocusChangeComplete() { | 69 void PageClickTracker::DidCompleteFocusChangeInFrame() { |
| 81 if (IsKeyboardAccessoryEnabled()) | 70 if (IsKeyboardAccessoryEnabled()) |
| 82 return; | 71 return; |
| 83 | 72 |
| 84 DoFocusChangeComplete(); | 73 DoFocusChangeComplete(); |
| 85 } | 74 } |
| 86 | 75 |
| 76 void PageClickTracker::DidReceiveLeftMouseDownOrGestureTapInNode( |
| 77 const blink::WebNode& node) { |
| 78 DCHECK(!node.IsNull()); |
| 79 focused_node_was_last_clicked_ = node.Focused(); |
| 80 |
| 81 if (IsKeyboardAccessoryEnabled()) |
| 82 DoFocusChangeComplete(); |
| 83 } |
| 84 |
| 87 void PageClickTracker::DoFocusChangeComplete() { | 85 void PageClickTracker::DoFocusChangeComplete() { |
| 88 WebElement focused_element = | 86 WebElement focused_element = |
| 89 render_frame()->GetWebFrame()->GetDocument().FocusedElement(); | 87 render_frame()->GetWebFrame()->GetDocument().FocusedElement(); |
| 90 if (focused_node_was_last_clicked_ && !focused_element.IsNull()) { | 88 if (focused_node_was_last_clicked_ && !focused_element.IsNull()) { |
| 91 const WebFormControlElement control = | 89 const WebFormControlElement control = |
| 92 GetTextFormControlElement(focused_element); | 90 GetTextFormControlElement(focused_element); |
| 93 if (!control.IsNull()) { | 91 if (!control.IsNull()) { |
| 94 listener_->FormControlElementClicked(control, | 92 listener_->FormControlElementClicked(control, |
| 95 was_focused_before_now_); | 93 was_focused_before_now_); |
| 96 } | 94 } |
| 97 } | 95 } |
| 98 | 96 |
| 99 was_focused_before_now_ = true; | 97 was_focused_before_now_ = true; |
| 100 focused_node_was_last_clicked_ = false; | 98 focused_node_was_last_clicked_ = false; |
| 101 } | 99 } |
| 102 | 100 |
| 103 void PageClickTracker::OnDestruct() { | |
| 104 delete this; | |
| 105 } | |
| 106 | |
| 107 // PageClickTracker::Legacy ---------------------------------------------------- | |
| 108 | |
| 109 PageClickTracker::Legacy::Legacy(PageClickTracker* tracker) | |
| 110 : content::RenderViewObserver(tracker->render_frame()->GetRenderView()), | |
| 111 tracker_(tracker) { | |
| 112 } | |
| 113 | |
| 114 void PageClickTracker::Legacy::OnDestruct() { | |
| 115 // No-op. Don't delete |this|. | |
| 116 } | |
| 117 | |
| 118 void PageClickTracker::Legacy::OnMouseDown(const WebNode& mouse_down_node) { | |
| 119 tracker_->OnMouseDown(mouse_down_node); | |
| 120 } | |
| 121 | |
| 122 void PageClickTracker::Legacy::FocusChangeComplete() { | |
| 123 tracker_->FocusChangeComplete(); | |
| 124 } | |
| 125 | |
| 126 } // namespace autofill | 101 } // namespace autofill |
| OLD | NEW |