Chromium Code Reviews| 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" | 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 AutofillPopupView::AutofillPopupView( | 15 AutofillPopupView::AutofillPopupView( |
| 16 content::WebContents* web_contents, | 16 content::WebContents* web_contents, |
| 17 AutofillExternalDelegate* external_delegate) | 17 AutofillExternalDelegate* external_delegate) |
| 18 : external_delegate_(external_delegate), | 18 : external_delegate_(external_delegate), |
| 19 selected_line_(-1) { | 19 selected_line_(-1) { |
|
Ilya Sherman
2012/03/21 23:35:30
nit: Please use the named constant here.
csharp
2012/03/23 15:10:52
Done.
| |
| 20 if (!web_contents) | |
| 21 return; | |
| 22 | |
| 20 registrar_.Add(this, | 23 registrar_.Add(this, |
| 21 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, | 24 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, |
| 22 content::Source<content::WebContents>(web_contents)); | 25 content::Source<content::WebContents>(web_contents)); |
| 23 registrar_.Add( | 26 registrar_.Add( |
| 24 this, | 27 this, |
| 25 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 28 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 26 content::Source<content::NavigationController>( | 29 content::Source<content::NavigationController>( |
| 27 &(web_contents->GetController()))); | 30 &(web_contents->GetController()))); |
| 28 } | 31 } |
| 29 | 32 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 47 | 50 |
| 48 separator_index_ = separator_index; | 51 separator_index_ = separator_index; |
| 49 | 52 |
| 50 ShowInternal(); | 53 ShowInternal(); |
| 51 } | 54 } |
| 52 | 55 |
| 53 void AutofillPopupView::SetSelectedLine(int selected_line) { | 56 void AutofillPopupView::SetSelectedLine(int selected_line) { |
| 54 if (selected_line_ == selected_line) | 57 if (selected_line_ == selected_line) |
| 55 return; | 58 return; |
| 56 | 59 |
| 57 if (selected_line_ != -1) | 60 if (selected_line_ != kNoSelection) |
| 58 InvalidateRow(selected_line_); | 61 InvalidateRow(selected_line_); |
| 59 | 62 |
| 60 if (selected_line != -1) | 63 if (selected_line != kNoSelection) |
| 61 InvalidateRow(selected_line); | 64 InvalidateRow(selected_line); |
| 62 | 65 |
| 63 selected_line_ = selected_line; | 66 selected_line_ = selected_line; |
| 64 | 67 |
| 65 if (selected_line_ != -1) { | 68 if (selected_line_ != kNoSelection) { |
| 66 external_delegate_->SelectAutofillSuggestionAtIndex( | 69 external_delegate_->SelectAutofillSuggestionAtIndex( |
| 67 autofill_unique_ids_[selected_line_], | 70 autofill_unique_ids_[selected_line_], |
| 68 selected_line); | 71 selected_line); |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| 75 void AutofillPopupView::SelectNextLine() { | |
| 76 int new_selected_line = selected_line_ + 1; | |
| 77 | |
| 78 if (new_selected_line == static_cast<int>(autofill_values_.size())) | |
| 79 new_selected_line = kNoSelection; | |
| 80 | |
| 81 SetSelectedLine(new_selected_line); | |
| 82 } | |
| 83 | |
| 84 void AutofillPopupView::SelectPreviousLine() { | |
| 85 int new_selected_line = selected_line_ - 1; | |
| 86 | |
| 87 if (new_selected_line < kNoSelection) | |
| 88 new_selected_line = autofill_values_.size() - 1; | |
| 89 | |
| 90 SetSelectedLine(new_selected_line); | |
| 91 } | |
| 92 | |
| 93 void AutofillPopupView::AcceptSelectedLine() { | |
| 94 DCHECK(selected_line_ >= 0 && | |
| 95 selected_line_ < static_cast<int>(autofill_values_.size())); | |
|
Ilya Sherman
2012/03/21 23:35:30
nit: Please write this as a DCHECK_GE and DCHECK_L
csharp
2012/03/23 15:10:52
Done.
| |
| 96 | |
| 97 external_delegate()->DidAcceptAutofillSuggestions( | |
| 98 autofill_values_[selected_line_], | |
| 99 autofill_unique_ids_[selected_line_], | |
| 100 selected_line_); | |
| 101 } | |
| 102 | |
| 103 void AutofillPopupView::RemoveLine(int line) { | |
| 104 // TODO(csharp) add removal code. | |
| 105 } | |
| 106 | |
| 72 void AutofillPopupView::Observe(int type, | 107 void AutofillPopupView::Observe(int type, |
| 73 const content::NotificationSource& source, | 108 const content::NotificationSource& source, |
| 74 const content::NotificationDetails& details) { | 109 const content::NotificationDetails& details) { |
| 75 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN | 110 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN |
| 76 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) | 111 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) |
| 77 Hide(); | 112 Hide(); |
| 78 } | 113 } |
| OLD | NEW |