OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autofill/autofill_popup_view.h" | 5 #include "chrome/browser/autofill/autofill_popup_view.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "chrome/browser/autofill/autofill_external_delegate.h" | |
7 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
8 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
9 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
11 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
12 | 14 |
13 AutofillPopupView::AutofillPopupView(content::WebContents* web_contents) { | 15 AutofillPopupView::AutofillPopupView( |
16 content::WebContents* web_contents, | |
17 AutofillExternalDelegate* external_delegate) | |
18 : external_delegate_(external_delegate), | |
19 selected_line_(-1) { | |
14 registrar_.Add(this, | 20 registrar_.Add(this, |
15 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, | 21 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, |
16 content::Source<content::WebContents>(web_contents)); | 22 content::Source<content::WebContents>(web_contents)); |
17 registrar_.Add( | 23 registrar_.Add( |
18 this, | 24 this, |
19 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 25 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
20 content::Source<content::NavigationController>( | 26 content::Source<content::NavigationController>( |
21 &(web_contents->GetController()))); | 27 &(web_contents->GetController()))); |
22 } | 28 } |
23 | 29 |
24 AutofillPopupView::~AutofillPopupView() {} | 30 AutofillPopupView::~AutofillPopupView() {} |
25 | 31 |
32 void AutofillPopupView::Hide() { | |
33 HideInternal(); | |
34 | |
35 external_delegate_->ClearPreviewedForm(); | |
36 } | |
37 | |
26 void AutofillPopupView::Show(const std::vector<string16>& autofill_values, | 38 void AutofillPopupView::Show(const std::vector<string16>& autofill_values, |
27 const std::vector<string16>& autofill_labels, | 39 const std::vector<string16>& autofill_labels, |
28 const std::vector<string16>& autofill_icons, | 40 const std::vector<string16>& autofill_icons, |
29 const std::vector<int>& autofill_unique_ids, | 41 const std::vector<int>& autofill_unique_ids, |
30 int separator_index) { | 42 int separator_index) { |
31 autofill_values_ = autofill_values; | 43 autofill_values_ = autofill_values; |
32 autofill_labels_ = autofill_labels; | 44 autofill_labels_ = autofill_labels; |
33 autofill_icons_ = autofill_icons; | 45 autofill_icons_ = autofill_icons; |
34 autofill_unique_ids_ = autofill_unique_ids; | 46 autofill_unique_ids_ = autofill_unique_ids; |
35 | 47 |
36 separator_index_ = separator_index; | 48 separator_index_ = separator_index; |
37 | 49 |
38 ShowInternal(); | 50 ShowInternal(); |
39 } | 51 } |
40 | 52 |
53 void AutofillPopupView::SetSelectedLine(int selected_line) { | |
54 if (selected_line_ == selected_line) | |
55 return; | |
56 | |
57 if (selected_line_ != -1) | |
58 InvalidateRow(selected_line_); | |
59 | |
60 if (selected_line != -1) | |
61 InvalidateRow(selected_line); | |
62 | |
63 selected_line_ = selected_line; | |
64 | |
65 if (selected_line_ != -1) | |
Ilya Sherman
2012/02/07 23:35:55
nit: Please add curly braces, since the body of th
csharp
2012/02/08 16:11:16
Done.
| |
66 external_delegate_->SelectAutofillSuggestionAtIndex( | |
67 autofill_unique_ids_[selected_line_], | |
68 selected_line); | |
69 } | |
70 | |
41 void AutofillPopupView::Observe(int type, | 71 void AutofillPopupView::Observe(int type, |
42 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
43 const content::NotificationDetails& details) { | 73 const content::NotificationDetails& details) { |
44 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN | 74 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN |
45 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) | 75 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) |
46 Hide(); | 76 Hide(); |
47 } | 77 } |
OLD | NEW |