1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/autofill/autofill_external_delegate_gtk.h"
#include "chrome/browser/ui/gtk/autofill/autofill_popup_view_gtk.h"
#include "chrome/browser/ui/gtk/gtk_theme_service.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
AutofillExternalDelegate* AutofillExternalDelegate::Create(
TabContentsWrapper* tab_contents_wrapper,
AutofillManager* autofill_manager) {
return new AutofillExternalDelegateGtk(tab_contents_wrapper,
autofill_manager);
}
AutofillExternalDelegateGtk::AutofillExternalDelegateGtk(
TabContentsWrapper* tab_contents_wrapper,
AutofillManager* autofill_manager)
: AutofillExternalDelegate(tab_contents_wrapper, autofill_manager),
web_contents_(tab_contents_wrapper->web_contents()),
event_handler_id_(0) {
tab_native_view_ = web_contents_->GetView()->GetNativeView();
}
AutofillExternalDelegateGtk::~AutofillExternalDelegateGtk() {
}
void AutofillExternalDelegateGtk::HideAutofillPopupInternal() {
if (!view_.get())
return;
view_->Hide();
view_.reset();
GtkWidget* toplevel = gtk_widget_get_toplevel(tab_native_view_);
g_signal_handler_disconnect(toplevel, event_handler_id_);
}
void AutofillExternalDelegateGtk::OnQueryPlatformSpecific(
int query_id,
const webkit::forms::FormData& form,
const webkit::forms::FormField& field,
const gfx::Rect& bounds) {
CreateViewIfNeeded();
view_->set_element_bounds(bounds);
}
void AutofillExternalDelegateGtk::ApplyAutofillSuggestions(
const std::vector<string16>& autofill_values,
const std::vector<string16>& autofill_labels,
const std::vector<string16>& autofill_icons,
const std::vector<int>& autofill_unique_ids) {
view_->Show(autofill_values,
autofill_labels,
autofill_icons,
autofill_unique_ids);
}
void AutofillExternalDelegateGtk::SetBounds(const gfx::Rect& bounds) {
CreateViewIfNeeded();
view_->set_element_bounds(bounds);
}
void AutofillExternalDelegateGtk::CreateViewIfNeeded() {
if (view_.get())
return;
view_.reset(new AutofillPopupViewGtk(web_contents_,
GtkThemeService::GetFrom(profile()),
this,
tab_native_view_));
GtkWidget* toplevel = gtk_widget_get_toplevel(tab_native_view_);
if (!g_signal_handler_is_connected(toplevel, event_handler_id_)) {
event_handler_id_ = g_signal_connect(
toplevel,
"focus-out-event",
G_CALLBACK(HandleViewFocusOutThunk),
this);
}
}
gboolean AutofillExternalDelegateGtk::HandleViewFocusOut(GtkWidget* sender,
GdkEventFocus* event) {
HideAutofillPopup();
return TRUE;
}
|