Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/autofill/autofill_popup_view.cc

Issue 9432029: GTK Keyboard Support for New Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 7 #include "base/logging.h"
8 #include "chrome/browser/autofill/autofill_external_delegate.h" 8 #include "chrome/browser/autofill/autofill_external_delegate.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_source.h" 12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
14 14
15 namespace {
16
17 // Used to indicate that no line is currently selected by the user.
18 const int kNoSelection = -1;
19
20 } // end namespace
21
15 AutofillPopupView::AutofillPopupView( 22 AutofillPopupView::AutofillPopupView(
16 content::WebContents* web_contents, 23 content::WebContents* web_contents,
17 AutofillExternalDelegate* external_delegate) 24 AutofillExternalDelegate* external_delegate)
18 : external_delegate_(external_delegate), 25 : external_delegate_(external_delegate),
19 selected_line_(-1) { 26 selected_line_(kNoSelection) {
27 if (!web_contents)
28 return;
29
20 registrar_.Add(this, 30 registrar_.Add(this,
21 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, 31 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
22 content::Source<content::WebContents>(web_contents)); 32 content::Source<content::WebContents>(web_contents));
23 registrar_.Add( 33 registrar_.Add(
24 this, 34 this,
25 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 35 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
26 content::Source<content::NavigationController>( 36 content::Source<content::NavigationController>(
27 &(web_contents->GetController()))); 37 &(web_contents->GetController())));
28 } 38 }
29 39
(...skipping 17 matching lines...) Expand all
47 57
48 separator_index_ = separator_index; 58 separator_index_ = separator_index;
49 59
50 ShowInternal(); 60 ShowInternal();
51 } 61 }
52 62
53 void AutofillPopupView::SetSelectedLine(int selected_line) { 63 void AutofillPopupView::SetSelectedLine(int selected_line) {
54 if (selected_line_ == selected_line) 64 if (selected_line_ == selected_line)
55 return; 65 return;
56 66
57 if (selected_line_ != -1) 67 if (selected_line_ != kNoSelection)
58 InvalidateRow(selected_line_); 68 InvalidateRow(selected_line_);
59 69
60 if (selected_line != -1) 70 if (selected_line != kNoSelection)
61 InvalidateRow(selected_line); 71 InvalidateRow(selected_line);
62 72
63 selected_line_ = selected_line; 73 selected_line_ = selected_line;
64 74
65 if (selected_line_ != -1) { 75 if (selected_line_ != kNoSelection) {
66 external_delegate_->SelectAutofillSuggestionAtIndex( 76 external_delegate_->SelectAutofillSuggestionAtIndex(
67 autofill_unique_ids_[selected_line_], 77 autofill_unique_ids_[selected_line_],
68 selected_line); 78 selected_line);
69 } 79 }
70 } 80 }
71 81
82 void AutofillPopupView::SelectNextLine() {
83 int new_selected_line = selected_line_ + 1;
84
85 if (new_selected_line == static_cast<int>(autofill_values_.size()))
86 new_selected_line = 0;
87
88 SetSelectedLine(new_selected_line);
89 }
90
91 void AutofillPopupView::SelectPreviousLine() {
92 int new_selected_line = selected_line_ - 1;
93
94 if (new_selected_line <= kNoSelection)
95 new_selected_line = autofill_values_.size() - 1;
96
97 SetSelectedLine(new_selected_line);
98 }
99
100 bool AutofillPopupView::AcceptSelectedLine() {
101 if (selected_line_ == kNoSelection)
102 return false;
103
104 DCHECK_GE(selected_line_, 0);
105 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size()));
106
107 return external_delegate()->DidAcceptAutofillSuggestions(
108 autofill_values_[selected_line_],
109 autofill_unique_ids_[selected_line_],
110 selected_line_);
111 }
112
113 bool AutofillPopupView::RemoveSelectedLine() {
114 if (selected_line_ == kNoSelection)
115 return false;
116
117 // TODO(csharp) add removal code.
118 return false;
119 }
120
72 void AutofillPopupView::Observe(int type, 121 void AutofillPopupView::Observe(int type,
73 const content::NotificationSource& source, 122 const content::NotificationSource& source,
74 const content::NotificationDetails& details) { 123 const content::NotificationDetails& details) {
75 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN 124 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN
76 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) 125 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED)
77 Hide(); 126 Hide();
78 } 127 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_popup_view.h ('k') | chrome/browser/autofill/autofill_popup_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698