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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 | 556 |
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]; |
rohitrao (ping after 24h)
2017/06/14 14:54:11
I don't understand this code at all. Why do we ne
justincohen
2017/06/14 16:44:08
material design! we lay out the rows ourselves be
| |
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 [UIView performWithoutAnimation:^{ |
rohitrao (ping after 24h)
2017/06/14 14:54:11
Please add a comment explaining what's going on he
justincohen
2017/06/14 16:44:08
Done.
| |
572 const AutocompleteMatch& match = | 569 [self.tableView beginUpdates]; |
573 ((const AutocompleteResult&)_currentResult).match_at((NSUInteger)i); | 570 for (size_t i = 0; i < kRowCount; i++) { |
574 [self updateRow:row withMatch:match]; | 571 OmniboxPopupMaterialRow* row = _rows[i]; |
575 row.hidden = NO; | 572 |
576 } else { | 573 if (i < size) { |
577 row.hidden = YES; | 574 const AutocompleteMatch& match = |
575 ((const AutocompleteResult&)_currentResult).match_at((NSUInteger)i); | |
576 [self updateRow:row withMatch:match]; | |
577 row.hidden = NO; | |
578 } else { | |
579 row.hidden = YES; | |
580 } | |
578 } | 581 } |
579 } | 582 [self.tableView endUpdates]; |
580 [self.tableView endUpdates]; | 583 }]; |
581 | 584 |
582 if (IsIPadIdiom()) | 585 if (IsIPadIdiom()) |
583 [self updateContentInsetForKeyboard]; | 586 [self updateContentInsetForKeyboard]; |
584 } | 587 } |
585 | 588 |
586 - (void)keyboardDidShow:(NSNotification*)notification { | 589 - (void)keyboardDidShow:(NSNotification*)notification { |
587 NSDictionary* keyboardInfo = [notification userInfo]; | 590 NSDictionary* keyboardInfo = [notification userInfo]; |
588 NSValue* keyboardFrameValue = | 591 NSValue* keyboardFrameValue = |
589 [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey]; | 592 [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey]; |
590 keyboardHeight_ = CurrentKeyboardHeight(keyboardFrameValue); | 593 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 | 652 // Make a defensive copy of |match.contents|, as CopyToOmnibox() will trigger |
650 // a new round of autocomplete and modify |_currentResult|. | 653 // a new round of autocomplete and modify |_currentResult|. |
651 base::string16 contents(match.contents); | 654 base::string16 contents(match.contents); |
652 _popupView->CopyToOmnibox(contents); | 655 _popupView->CopyToOmnibox(contents); |
653 } | 656 } |
654 | 657 |
655 #pragma mark - | 658 #pragma mark - |
656 #pragma mark UIScrollViewDelegate | 659 #pragma mark UIScrollViewDelegate |
657 | 660 |
658 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { | 661 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { |
659 // Setting the top inset of the scrollView to |kTopAndBottomPadding| causes a | 662 if (!scrollView.dragging) |
rohitrao (ping after 24h)
2017/06/14 14:54:11
Nice, this feels much cleaner.
justincohen
2017/06/14 16:44:08
good, not planning on putting this or above behind
| |
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; | 663 return; |
664 | 664 |
665 _popupView->DidScroll(); | 665 _popupView->DidScroll(); |
666 for (OmniboxPopupMaterialRow* row in _rows) { | 666 for (OmniboxPopupMaterialRow* row in _rows) { |
667 row.highlighted = NO; | 667 row.highlighted = NO; |
668 } | 668 } |
669 } | 669 } |
670 | 670 |
671 // Set text alignment for popup cells. | 671 // Set text alignment for popup cells. |
672 - (void)setTextAlignment:(NSTextAlignment)alignment { | 672 - (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. | 786 // The delete button never disappears if you don't call this after a tap. |
787 // It doesn't seem to be required anywhere else. | 787 // It doesn't seem to be required anywhere else. |
788 [_rows[indexPath.row] prepareForReuse]; | 788 [_rows[indexPath.row] prepareForReuse]; |
789 const AutocompleteMatch& match = | 789 const AutocompleteMatch& match = |
790 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); | 790 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); |
791 _popupView->DeleteMatch(match); | 791 _popupView->DeleteMatch(match); |
792 } | 792 } |
793 } | 793 } |
794 | 794 |
795 @end | 795 @end |
OLD | NEW |