This source file includes following definitions.
- GetTextWebInputElement
 
- GetTextWebTextAreaElement
 
- DidSelectedTextFieldLoseFocus
 
- listener_
 
- DidHandleMouseEvent
 
- DidFinishDocumentLoad
 
- FrameDetached
 
- handleEvent
 
- HandleTextFieldMaybeLosingFocus
 
#include "components/autofill/content/renderer/page_click_tracker.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
#include "components/autofill/content/renderer/page_click_listener.h"
#include "content/public/renderer/render_view.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebDOMMouseEvent.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebInputElement.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/WebKit/public/web/WebTextAreaElement.h"
#include "third_party/WebKit/public/web/WebView.h"
using blink::WebDOMEvent;
using blink::WebDOMMouseEvent;
using blink::WebElement;
using blink::WebFormControlElement;
using blink::WebFrame;
using blink::WebInputElement;
using blink::WebInputEvent;
using blink::WebMouseEvent;
using blink::WebNode;
using blink::WebString;
using blink::WebTextAreaElement;
using blink::WebView;
namespace {
const WebInputElement GetTextWebInputElement(const WebNode& node) {
  if (!node.isElementNode())
    return WebInputElement();
  const WebElement element = node.toConst<WebElement>();
  if (!element.hasTagName("input"))
    return WebInputElement();
  const WebInputElement* input = blink::toWebInputElement(&element);
  if (!autofill::IsTextInput(input))
    return WebInputElement();
  return *input;
}
const WebTextAreaElement GetTextWebTextAreaElement(const WebNode& node) {
  if (!node.isElementNode())
    return WebTextAreaElement();
  const WebElement element = node.toConst<WebElement>();
  if (!element.hasTagName("textarea"))
    return WebTextAreaElement();
  return element.toConst<WebTextAreaElement>();
}
bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) {
  blink::WebElement focused_element =
    newly_clicked_node.document().focusedElement();
  if (focused_element.isNull() ||
      (GetTextWebInputElement(focused_element).isNull() &&
       GetTextWebTextAreaElement(focused_element).isNull()))
    return false;
  return focused_element != newly_clicked_node;
}
}  
namespace autofill {
PageClickTracker::PageClickTracker(content::RenderView* render_view,
                                   PageClickListener* listener)
    : content::RenderViewObserver(render_view),
      was_focused_(false),
      listener_(listener) {
}
PageClickTracker::~PageClickTracker() {
  
  
  
  
  
  
}
void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) {
  if (event.type != WebInputEvent::MouseDown ||
      last_node_clicked_.isNull()) {
    return;
  }
  
  const WebInputElement input_element =
      GetTextWebInputElement(last_node_clicked_);
  const WebTextAreaElement textarea_element =
      GetTextWebTextAreaElement(last_node_clicked_);
  if (input_element.isNull() && textarea_element.isNull())
    return;
  if (!input_element.isNull())
    listener_->FormControlElementClicked(input_element, was_focused_);
  else if (!textarea_element.isNull())
    listener_->FormControlElementClicked(textarea_element, was_focused_);
}
void PageClickTracker::DidFinishDocumentLoad(blink::WebFrame* frame) {
  tracked_frames_.push_back(frame);
  frame->document().addEventListener("mousedown", this, false);
}
void PageClickTracker::FrameDetached(blink::WebFrame* frame) {
  std::vector<blink::WebFrame*>::iterator iter =
      std::find(tracked_frames_.begin(), tracked_frames_.end(), frame);
  if (iter == tracked_frames_.end()) {
    
    
    
    return;
  }
  tracked_frames_.erase(iter);
}
void PageClickTracker::handleEvent(const WebDOMEvent& event) {
  last_node_clicked_.reset();
  if (!event.isMouseEvent())
    return;
  const WebDOMMouseEvent mouse_event = event.toConst<WebDOMMouseEvent>();
  DCHECK(mouse_event.buttonDown());
  if (mouse_event.button() != 0)
    return;  
  
  
  
  WebNode node = mouse_event.target();
  if (node.isNull())
    
    
    return;
  HandleTextFieldMaybeLosingFocus(node);
  
  if (GetTextWebInputElement(node).isNull() &&
      GetTextWebTextAreaElement(node).isNull())
    return;
  last_node_clicked_ = node;
  was_focused_ = (node.document().focusedElement() == last_node_clicked_);
}
void PageClickTracker::HandleTextFieldMaybeLosingFocus(
    const WebNode& newly_clicked_node) {
  if (DidSelectedTextFieldLoseFocus(newly_clicked_node))
    listener_->FormControlElementLostFocus();
}
}