Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_view_controller.h" | 5 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 29 | 29 |
| 30 #if !defined(__has_feature) || !__has_feature(objc_arc) | 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 31 #error "This file requires ARC support." | 31 #error "This file requires ARC support." |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 const int kRowCount = 6; | 35 const int kRowCount = 6; |
| 36 const CGFloat kRowHeight = 48.0; | 36 const CGFloat kRowHeight = 48.0; |
| 37 const CGFloat kAnswerRowHeight = 64.0; | 37 const CGFloat kAnswerRowHeight = 64.0; |
| 38 const CGFloat kTopAndBottomPadding = 8.0; | 38 const CGFloat kTopAndBottomPadding = 8.0; |
|
rohitrao (ping after 24h)
2017/06/14 16:47:03
Why do we need to inset with this padding? If you
| |
| 39 // The color of the main text of a suggest cell. | 39 // The color of the main text of a suggest cell. |
| 40 UIColor* SuggestionTextColor() { | 40 UIColor* SuggestionTextColor() { |
| 41 return [UIColor colorWithWhite:(51 / 255.0) alpha:1.0]; | 41 return [UIColor colorWithWhite:(51 / 255.0) alpha:1.0]; |
| 42 } | 42 } |
| 43 // The color of the detail text of a suggest cell. | 43 // The color of the detail text of a suggest cell. |
| 44 UIColor* SuggestionDetailTextColor() { | 44 UIColor* SuggestionDetailTextColor() { |
| 45 return [UIColor colorWithRed:(85 / 255.0) | 45 return [UIColor colorWithRed:(85 / 255.0) |
| 46 green:(149 / 255.0) | 46 green:(149 / 255.0) |
| 47 blue:(254 / 255.0) | 47 blue:(254 / 255.0) |
| 48 alpha:1.0]; | 48 alpha:1.0]; |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 size_t size = _currentResult.size(); | 557 size_t size = _currentResult.size(); |
| 558 if (animation && size > 0) { | 558 if (animation && size > 0) { |
| 559 [self fadeInRows]; | 559 [self fadeInRows]; |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 - (void)layoutRows { | 563 - (void)layoutRows { |
| 564 size_t size = _currentResult.size(); | 564 size_t size = _currentResult.size(); |
| 565 | 565 |
| 566 [self.tableView reloadData]; | 566 [self.tableView reloadData]; |
| 567 [self.tableView beginUpdates]; | |
| 568 for (size_t i = 0; i < kRowCount; i++) { | |
| 569 OmniboxPopupMaterialRow* row = _rows[i]; | |
| 570 | 567 |
| 571 if (i < size) { | 568 // We animate the rows ourselves in -fadeInRows, so make sure the table view |
| 572 const AutocompleteMatch& match = | 569 // doens't try to apply it's own animation. |
|
rohitrao (ping after 24h)
2017/06/14 16:47:03
doesn't and its.
| |
| 573 ((const AutocompleteResult&)_currentResult).match_at((NSUInteger)i); | 570 [UIView performWithoutAnimation:^{ |
| 574 [self updateRow:row withMatch:match]; | 571 [self.tableView beginUpdates]; |
| 575 row.hidden = NO; | 572 for (size_t i = 0; i < kRowCount; i++) { |
| 576 } else { | 573 OmniboxPopupMaterialRow* row = _rows[i]; |
| 577 row.hidden = YES; | 574 |
| 575 if (i < size) { | |
| 576 const AutocompleteMatch& match = | |
| 577 ((const AutocompleteResult&)_currentResult).match_at((NSUInteger)i); | |
| 578 [self updateRow:row withMatch:match]; | |
| 579 row.hidden = NO; | |
| 580 } else { | |
| 581 row.hidden = YES; | |
| 582 } | |
| 578 } | 583 } |
| 579 } | 584 [self.tableView endUpdates]; |
| 580 [self.tableView endUpdates]; | 585 }]; |
| 581 | 586 |
| 582 if (IsIPadIdiom()) | 587 if (IsIPadIdiom()) |
| 583 [self updateContentInsetForKeyboard]; | 588 [self updateContentInsetForKeyboard]; |
| 584 } | 589 } |
| 585 | 590 |
| 586 - (void)keyboardDidShow:(NSNotification*)notification { | 591 - (void)keyboardDidShow:(NSNotification*)notification { |
| 587 NSDictionary* keyboardInfo = [notification userInfo]; | 592 NSDictionary* keyboardInfo = [notification userInfo]; |
| 588 NSValue* keyboardFrameValue = | 593 NSValue* keyboardFrameValue = |
| 589 [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey]; | 594 [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey]; |
| 590 keyboardHeight_ = CurrentKeyboardHeight(keyboardFrameValue); | 595 keyboardHeight_ = CurrentKeyboardHeight(keyboardFrameValue); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 // Make a defensive copy of |match.contents|, as CopyToOmnibox() will trigger | 654 // Make a defensive copy of |match.contents|, as CopyToOmnibox() will trigger |
| 650 // a new round of autocomplete and modify |_currentResult|. | 655 // a new round of autocomplete and modify |_currentResult|. |
| 651 base::string16 contents(match.contents); | 656 base::string16 contents(match.contents); |
| 652 _popupView->CopyToOmnibox(contents); | 657 _popupView->CopyToOmnibox(contents); |
| 653 } | 658 } |
| 654 | 659 |
| 655 #pragma mark - | 660 #pragma mark - |
| 656 #pragma mark UIScrollViewDelegate | 661 #pragma mark UIScrollViewDelegate |
| 657 | 662 |
| 658 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { | 663 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { |
| 659 // Setting the top inset of the scrollView to |kTopAndBottomPadding| causes a | 664 if (!scrollView.dragging) |
|
rohitrao (ping after 24h)
2017/06/14 16:47:03
Please add a comment here explaining why we need t
| |
| 660 // one time scrollViewDidScroll to |-kTopAndBottomPadding|. It's easier to | |
| 661 // just ignore this one scroll tick. | |
| 662 if (scrollView.contentOffset.y == 0 - kTopAndBottomPadding) | |
| 663 return; | 665 return; |
| 664 | 666 |
| 665 _popupView->DidScroll(); | 667 _popupView->DidScroll(); |
| 666 for (OmniboxPopupMaterialRow* row in _rows) { | 668 for (OmniboxPopupMaterialRow* row in _rows) { |
| 667 row.highlighted = NO; | 669 row.highlighted = NO; |
| 668 } | 670 } |
| 669 } | 671 } |
| 670 | 672 |
| 671 // Set text alignment for popup cells. | 673 // Set text alignment for popup cells. |
| 672 - (void)setTextAlignment:(NSTextAlignment)alignment { | 674 - (void)setTextAlignment:(NSTextAlignment)alignment { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 // The delete button never disappears if you don't call this after a tap. | 788 // The delete button never disappears if you don't call this after a tap. |
| 787 // It doesn't seem to be required anywhere else. | 789 // It doesn't seem to be required anywhere else. |
| 788 [_rows[indexPath.row] prepareForReuse]; | 790 [_rows[indexPath.row] prepareForReuse]; |
| 789 const AutocompleteMatch& match = | 791 const AutocompleteMatch& match = |
| 790 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); | 792 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); |
| 791 _popupView->DeleteMatch(match); | 793 _popupView->DeleteMatch(match); |
| 792 } | 794 } |
| 793 } | 795 } |
| 794 | 796 |
| 795 @end | 797 @end |
| OLD | NEW |