add ability to open popup on second click
This commit is contained in:
parent
4949531f57
commit
a95d6b997b
2 changed files with 71 additions and 6 deletions
|
@ -53,10 +53,17 @@ AutofillAgent::AutofillAgent(
|
|||
content::RenderFrame* frame)
|
||||
: content::RenderFrameObserver(frame),
|
||||
render_frame_(frame),
|
||||
helper_(new Helper(this)),
|
||||
focused_node_was_last_clicked_(false),
|
||||
was_focused_before_now_(false),
|
||||
weak_ptr_factory_(this) {
|
||||
render_frame_->GetWebFrame()->setAutofillClient(this);
|
||||
}
|
||||
|
||||
AutofillAgent::~AutofillAgent() {
|
||||
delete helper_;
|
||||
}
|
||||
|
||||
void AutofillAgent::OnDestruct() {
|
||||
delete this;
|
||||
}
|
||||
|
@ -66,6 +73,7 @@ void AutofillAgent::DidChangeScrollOffset() {
|
|||
}
|
||||
|
||||
void AutofillAgent::FocusedNodeChanged(const blink::WebNode&) {
|
||||
was_focused_before_now_ = false;
|
||||
HidePopup();
|
||||
}
|
||||
|
||||
|
@ -161,12 +169,17 @@ void AutofillAgent::ShowSuggestions(
|
|||
ShowPopup(element, data_list_values, data_list_labels);
|
||||
}
|
||||
|
||||
void AutofillAgent::OnAcceptSuggestion(base::string16 suggestion) {
|
||||
auto element = render_frame_->GetWebFrame()->document().focusedElement();
|
||||
if (element.isFormControlElement()) {
|
||||
toWebInputElement(&element)->setAutofillValue(
|
||||
blink::WebString::fromUTF16(suggestion));
|
||||
}
|
||||
AutofillAgent::Helper::Helper(AutofillAgent* agent)
|
||||
: content::RenderViewObserver(agent->render_frame_->GetRenderView()),
|
||||
agent_(agent) {
|
||||
}
|
||||
|
||||
void AutofillAgent::Helper::OnMouseDown(const blink::WebNode& node) {
|
||||
agent_->focused_node_was_last_clicked_ = !node.isNull() && node.focused();
|
||||
}
|
||||
|
||||
void AutofillAgent::Helper::FocusChangeComplete() {
|
||||
agent_->DoFocusChangeComplete();
|
||||
}
|
||||
|
||||
bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
|
||||
|
@ -204,4 +217,27 @@ void AutofillAgent::ShowPopup(
|
|||
web_contents_routing_id_, routing_id(), bounds, values, labels));
|
||||
}
|
||||
|
||||
void AutofillAgent::OnAcceptSuggestion(base::string16 suggestion) {
|
||||
auto element = render_frame_->GetWebFrame()->document().focusedElement();
|
||||
if (element.isFormControlElement()) {
|
||||
toWebInputElement(&element)->setAutofillValue(
|
||||
blink::WebString::fromUTF16(suggestion));
|
||||
}
|
||||
}
|
||||
|
||||
void AutofillAgent::DoFocusChangeComplete() {
|
||||
auto element = render_frame_->GetWebFrame()->document().focusedElement();
|
||||
if (element.isNull() || !element.isFormControlElement())
|
||||
return;
|
||||
|
||||
if (focused_node_was_last_clicked_ && was_focused_before_now_) {
|
||||
ShowSuggestionsOptions options;
|
||||
options.autofill_on_empty_values = true;
|
||||
ShowSuggestions(*toWebInputElement(&element), options);
|
||||
}
|
||||
|
||||
was_focused_before_now_ = true;
|
||||
focused_node_was_last_clicked_ = false;
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "content/public/renderer/render_frame_observer.h"
|
||||
#include "content/public/renderer/render_view_observer.h"
|
||||
#include "third_party/WebKit/public/web/WebAutofillClient.h"
|
||||
#include "third_party/WebKit/public/web/WebFormControlElement.h"
|
||||
#include "third_party/WebKit/public/web/WebInputElement.h"
|
||||
|
@ -20,6 +21,7 @@ class AutofillAgent : public content::RenderFrameObserver,
|
|||
public blink::WebAutofillClient {
|
||||
public:
|
||||
explicit AutofillAgent(content::RenderFrame* frame);
|
||||
~AutofillAgent();
|
||||
|
||||
// content::RenderFrameObserver:
|
||||
void OnDestruct() override;
|
||||
|
@ -28,6 +30,21 @@ class AutofillAgent : public content::RenderFrameObserver,
|
|||
void FocusedNodeChanged(const blink::WebNode&) override;
|
||||
|
||||
private:
|
||||
|
||||
class Helper : public content::RenderViewObserver {
|
||||
public:
|
||||
Helper(AutofillAgent* agent);
|
||||
|
||||
// content::RenderViewObserver implementation.
|
||||
void OnDestruct() override {}
|
||||
void OnMouseDown(const blink::WebNode&) override;
|
||||
void FocusChangeComplete() override;
|
||||
|
||||
private:
|
||||
AutofillAgent* agent_;
|
||||
};
|
||||
friend class Helper;
|
||||
|
||||
struct ShowSuggestionsOptions {
|
||||
ShowSuggestionsOptions();
|
||||
bool autofill_on_empty_values;
|
||||
|
@ -55,9 +72,21 @@ class AutofillAgent : public content::RenderFrameObserver,
|
|||
const ShowSuggestionsOptions& options);
|
||||
void OnAcceptSuggestion(base::string16 suggestion);
|
||||
|
||||
void DoFocusChangeComplete();
|
||||
|
||||
content::RenderFrame* render_frame_;
|
||||
int web_contents_routing_id_;
|
||||
|
||||
Helper* helper_;
|
||||
|
||||
// True when the last click was on the focused node.
|
||||
bool focused_node_was_last_clicked_;
|
||||
|
||||
// This is set to false when the focus changes, then set back to true soon
|
||||
// afterwards. This helps track whether an event happened after a node was
|
||||
// already focused, or if it caused the focus to change.
|
||||
bool was_focused_before_now_;
|
||||
|
||||
base::WeakPtrFactory<AutofillAgent> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AutofillAgent);
|
||||
|
|
Loading…
Reference in a new issue