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

Side by Side Diff: ios/chrome/browser/ui/omnibox/omnibox_popup_material_view_controller.mm

Issue 2674543002: Remove logo from Physical Web omnibox suggestions (Closed)
Patch Set: Created 3 years, 10 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) 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"
11 #include "base/mac/scoped_nsobject.h" 11 #include "base/mac/scoped_nsobject.h"
12 #include "base/metrics/user_metrics.h"
13 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "components/omnibox/browser/autocomplete_input.h" 14 #include "components/omnibox/browser/autocomplete_input.h"
16 #include "components/omnibox/browser/autocomplete_match.h" 15 #include "components/omnibox/browser/autocomplete_match.h"
17 #include "components/omnibox/browser/autocomplete_result.h" 16 #include "components/omnibox/browser/autocomplete_result.h"
18 #include "components/omnibox/browser/suggestion_answer.h" 17 #include "components/omnibox/browser/suggestion_answer.h"
19 #include "ios/chrome/browser/ui/animation_util.h" 18 #include "ios/chrome/browser/ui/animation_util.h"
20 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
21 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
22 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" 19 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h"
23 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h" 20 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h"
24 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" 21 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h"
25 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" 22 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h"
26 #include "ios/chrome/browser/ui/rtl_geometry.h" 23 #include "ios/chrome/browser/ui/rtl_geometry.h"
27 #include "ios/chrome/browser/ui/ui_util.h" 24 #include "ios/chrome/browser/ui/ui_util.h"
28 #import "ios/chrome/browser/ui/uikit_ui_util.h" 25 #import "ios/chrome/browser/ui/uikit_ui_util.h"
29 #include "ios/chrome/grit/ios_theme_resources.h" 26 #include "ios/chrome/grit/ios_theme_resources.h"
30 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 27 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
31 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 28 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 OmniboxPopupMaterialRow* row = [[[OmniboxPopupMaterialRow alloc] 176 OmniboxPopupMaterialRow* row = [[[OmniboxPopupMaterialRow alloc]
180 initWithIncognito:_incognito] autorelease]; 177 initWithIncognito:_incognito] autorelease];
181 row.accessibilityIdentifier = 178 row.accessibilityIdentifier =
182 [NSString stringWithFormat:@"omnibox suggestion %i", i]; 179 [NSString stringWithFormat:@"omnibox suggestion %i", i];
183 row.autoresizingMask = UIViewAutoresizingFlexibleWidth; 180 row.autoresizingMask = UIViewAutoresizingFlexibleWidth;
184 [rowsBuilder addObject:row]; 181 [rowsBuilder addObject:row];
185 [row.appendButton addTarget:self 182 [row.appendButton addTarget:self
186 action:@selector(appendButtonTapped:) 183 action:@selector(appendButtonTapped:)
187 forControlEvents:UIControlEventTouchUpInside]; 184 forControlEvents:UIControlEventTouchUpInside];
188 [row.appendButton setTag:i]; 185 [row.appendButton setTag:i];
189 [row.physicalWebButton addTarget:self
190 action:@selector(physicalWebButtonTapped:)
191 forControlEvents:UIControlEventTouchUpInside];
192 row.rowHeight = kRowHeight; 186 row.rowHeight = kRowHeight;
193 } 187 }
194 _rows.reset([rowsBuilder copy]); 188 _rows.reset([rowsBuilder copy]);
195 189
196 // Table configuration. 190 // Table configuration.
197 self.tableView.allowsMultipleSelectionDuringEditing = NO; 191 self.tableView.allowsMultipleSelectionDuringEditing = NO;
198 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 192 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
199 self.tableView.separatorInset = UIEdgeInsetsZero; 193 self.tableView.separatorInset = UIEdgeInsetsZero;
200 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { 194 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
201 [self.tableView setLayoutMargins:UIEdgeInsetsZero]; 195 [self.tableView setLayoutMargins:UIEdgeInsetsZero];
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 [textLabel setNeedsDisplay]; 365 [textLabel setNeedsDisplay];
372 366
373 // The leading image (e.g. magnifying glass, star, clock) is only shown on 367 // The leading image (e.g. magnifying glass, star, clock) is only shown on
374 // iPad. 368 // iPad.
375 if (IsIPadIdiom()) { 369 if (IsIPadIdiom()) {
376 int imageId = GetIconForAutocompleteMatchType( 370 int imageId = GetIconForAutocompleteMatchType(
377 match.type, _popupView->IsStarredMatch(match), _incognito); 371 match.type, _popupView->IsStarredMatch(match), _incognito);
378 [row updateLeadingImage:imageId]; 372 [row updateLeadingImage:imageId];
379 } 373 }
380 374
381 // Show append button for search history/search suggestions/voice search as 375 // Show append button for search history/search suggestions/Physical Web as
382 // the right control element (aka an accessory element of a table view cell). 376 // the right control element (aka an accessory element of a table view cell).
383 BOOL autocompleteSearchMatch = 377 BOOL appendableMatch = match.type == AutocompleteMatchType::SEARCH_HISTORY ||
384 match.type == AutocompleteMatchType::SEARCH_HISTORY || 378 match.type == AutocompleteMatchType::SEARCH_SUGGEST ||
385 match.type == AutocompleteMatchType::SEARCH_SUGGEST; 379 match.type == AutocompleteMatchType::PHYSICAL_WEB;
386 row.appendButton.hidden = !autocompleteSearchMatch; 380 row.appendButton.hidden = !appendableMatch;
387 [row.appendButton cancelTrackingWithEvent:nil]; 381 [row.appendButton cancelTrackingWithEvent:nil];
388 382
389 // Show the Physical Web logo as the right accessory image for Physical Web
390 // suggestions.
391 BOOL physicalWebMatch =
392 match.type == AutocompleteMatchType::PHYSICAL_WEB ||
393 match.type == AutocompleteMatchType::PHYSICAL_WEB_OVERFLOW;
394 row.physicalWebButton.hidden = !physicalWebMatch;
395 [row.physicalWebButton cancelTrackingWithEvent:nil];
396
397 // If a right accessory element is present or the text alignment is right 383 // If a right accessory element is present or the text alignment is right
398 // aligned, adjust the width to align with the accessory element. 384 // aligned, adjust the width to align with the accessory element.
399 if (autocompleteSearchMatch || physicalWebMatch || alignmentRight) { 385 if (appendableMatch || alignmentRight) {
400 LayoutRect layout = 386 LayoutRect layout =
401 LayoutRectForRectInBoundingRect(textLabel.frame, self.view.frame); 387 LayoutRectForRectInBoundingRect(textLabel.frame, self.view.frame);
402 layout.size.width -= kAppendButtonWidth; 388 layout.size.width -= kAppendButtonWidth;
403 textLabel.frame = LayoutRectGetRect(layout); 389 textLabel.frame = LayoutRectGetRect(layout);
404 layout = 390 layout =
405 LayoutRectForRectInBoundingRect(detailTextLabel.frame, self.view.frame); 391 LayoutRectForRectInBoundingRect(detailTextLabel.frame, self.view.frame);
406 layout.size.width -= 392 layout.size.width -=
407 kAppendButtonWidth + (answerImagePresent ? answerImagePadding : 0); 393 kAppendButtonWidth + (answerImagePresent ? answerImagePadding : 0);
408 detailTextLabel.frame = LayoutRectGetRect(layout); 394 detailTextLabel.frame = LayoutRectGetRect(layout);
409 } 395 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 - (void)appendButtonTapped:(id)sender { 632 - (void)appendButtonTapped:(id)sender {
647 NSUInteger row = [sender tag]; 633 NSUInteger row = [sender tag];
648 const AutocompleteMatch& match = 634 const AutocompleteMatch& match =
649 ((const AutocompleteResult&)_currentResult).match_at(row); 635 ((const AutocompleteResult&)_currentResult).match_at(row);
650 // Make a defensive copy of |match.contents|, as CopyToOmnibox() will trigger 636 // Make a defensive copy of |match.contents|, as CopyToOmnibox() will trigger
651 // a new round of autocomplete and modify |_currentResult|. 637 // a new round of autocomplete and modify |_currentResult|.
652 base::string16 contents(match.contents); 638 base::string16 contents(match.contents);
653 _popupView->CopyToOmnibox(contents); 639 _popupView->CopyToOmnibox(contents);
654 } 640 }
655 641
656 - (void)physicalWebButtonTapped:(id)sender {
657 base::scoped_nsobject<GenericChromeCommand> command([
658 [GenericChromeCommand alloc] initWithTag:IDC_SHOW_PHYSICAL_WEB_SETTINGS]);
rohitrao (ping after 24h) 2017/02/03 21:11:10 Is this the only place that we send this command?
mattreynolds 2017/02/03 22:41:45 Done.
659 [command executeOnMainWindow];
660
661 // Record when the user opens the Physical Web preference page from the
662 // omnibox suggestion.
663 base::RecordAction(base::UserMetricsAction("PhysicalWeb.Prefs.FromOmnibox"));
664 }
665
666 #pragma mark - 642 #pragma mark -
667 #pragma mark UIScrollViewDelegate 643 #pragma mark UIScrollViewDelegate
668 644
669 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { 645 - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
670 // Setting the top inset of the scrollView to |kTopAndBottomPadding| causes a 646 // Setting the top inset of the scrollView to |kTopAndBottomPadding| causes a
671 // one time scrollViewDidScroll to |-kTopAndBottomPadding|. It's easier to 647 // one time scrollViewDidScroll to |-kTopAndBottomPadding|. It's easier to
672 // just ignore this one scroll tick. 648 // just ignore this one scroll tick.
673 if (scrollView.contentOffset.y == 0 - kTopAndBottomPadding) 649 if (scrollView.contentOffset.y == 0 - kTopAndBottomPadding)
674 return; 650 return;
675 651
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 // The delete button never disappears if you don't call this after a tap. 782 // The delete button never disappears if you don't call this after a tap.
807 // It doesn't seem to be required anywhere else. 783 // It doesn't seem to be required anywhere else.
808 [_rows[indexPath.row] prepareForReuse]; 784 [_rows[indexPath.row] prepareForReuse];
809 const AutocompleteMatch& match = 785 const AutocompleteMatch& match =
810 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); 786 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row);
811 _popupView->DeleteMatch(match); 787 _popupView->DeleteMatch(match);
812 } 788 }
813 } 789 }
814 790
815 @end 791 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698