OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_scanner.h" | 5 #include "chrome/browser/autofill/autofill_scanner.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/autofill/autofill_field.h" | 8 #include "chrome/browser/autofill/autofill_field.h" |
9 | 9 |
10 AutofillScanner::AutofillScanner( | 10 AutofillScanner::AutofillScanner( |
11 const std::vector<const AutofillField*>& fields) | 11 const std::vector<const AutofillField*>& fields) |
12 : cursor_(fields.begin()), | 12 : cursor_(fields.begin()), |
13 saved_cursor_(fields.begin()), | 13 saved_cursor_(fields.begin()), |
14 begin_(fields.begin()), | 14 begin_(fields.begin()), |
15 end_(fields.end()) { | 15 end_(fields.end()) { |
16 } | 16 } |
17 | 17 |
18 AutofillScanner::~AutofillScanner() { | 18 AutofillScanner::~AutofillScanner() { |
19 } | 19 } |
20 | 20 |
21 void AutofillScanner::Advance() { | 21 void AutofillScanner::Advance() { |
| 22 SkipClickables(); |
22 DCHECK(!IsEnd()); | 23 DCHECK(!IsEnd()); |
23 ++cursor_; | 24 ++cursor_; |
24 } | 25 } |
25 | 26 |
26 const AutofillField* AutofillScanner::Cursor() const { | 27 const AutofillField* AutofillScanner::Cursor() { |
27 if (IsEnd()) { | 28 if (IsEnd()) { |
28 NOTREACHED(); | 29 NOTREACHED(); |
29 return NULL; | 30 return NULL; |
30 } | 31 } |
31 | 32 |
32 return *cursor_; | 33 return *cursor_; |
33 } | 34 } |
34 | 35 |
35 bool AutofillScanner::IsEnd() const { | 36 bool AutofillScanner::IsEnd() { |
| 37 SkipClickables(); |
36 return cursor_ == end_; | 38 return cursor_ == end_; |
37 } | 39 } |
38 | 40 |
39 void AutofillScanner::Rewind() { | 41 void AutofillScanner::Rewind() { |
40 DCHECK(saved_cursor_ != end_); | 42 DCHECK(saved_cursor_ != end_); |
41 cursor_ = saved_cursor_; | 43 cursor_ = saved_cursor_; |
42 saved_cursor_ = end_; | 44 saved_cursor_ = end_; |
43 } | 45 } |
44 | 46 |
45 void AutofillScanner::RewindTo(size_t index) { | 47 void AutofillScanner::RewindTo(size_t index) { |
46 DCHECK(index < static_cast<size_t>(end_ - begin_)); | 48 DCHECK(index < static_cast<size_t>(end_ - begin_)); |
47 cursor_ = begin_ + index; | 49 cursor_ = begin_ + index; |
48 saved_cursor_ = end_; | 50 saved_cursor_ = end_; |
49 } | 51 } |
50 | 52 |
51 size_t AutofillScanner::SaveCursor() { | 53 size_t AutofillScanner::SaveCursor() { |
52 saved_cursor_ = cursor_; | 54 saved_cursor_ = cursor_; |
53 return static_cast<size_t>(cursor_ - begin_); | 55 return static_cast<size_t>(cursor_ - begin_); |
54 } | 56 } |
| 57 |
| 58 void AutofillScanner::SkipClickables() { |
| 59 while (cursor_ != end_ && (*cursor_)->is_checkable) |
| 60 ++cursor_; |
| 61 } |
OLD | NEW |