Commit fb66dec3 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Replace kLocationBarBecomesFirstResponderNotification by direct calls

Only the current NTP should receive the keyboard events.
Replace the broadcast of notification by a direct call.

Bug: 1032999, 778008
Change-Id: I8d42fac5fe81cd08fc56742ebe01abe0989ff5c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2039412Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742113}
parent ac2930b3
...@@ -107,7 +107,6 @@ source_set("browser_view") { ...@@ -107,7 +107,6 @@ source_set("browser_view") {
"//ios/chrome/browser/ui/infobars:public", "//ios/chrome/browser/ui/infobars:public",
"//ios/chrome/browser/ui/keyboard", "//ios/chrome/browser/ui/keyboard",
"//ios/chrome/browser/ui/location_bar:location_bar_model_delegate", "//ios/chrome/browser/ui/location_bar:location_bar_model_delegate",
"//ios/chrome/browser/ui/location_bar:notifications",
"//ios/chrome/browser/ui/main_content:main_content_ui", "//ios/chrome/browser/ui/main_content:main_content_ui",
"//ios/chrome/browser/ui/main_content:main_content_ui_broadcasting_util", "//ios/chrome/browser/ui/main_content:main_content_ui_broadcasting_util",
"//ios/chrome/browser/ui/ntp", "//ios/chrome/browser/ui/ntp",
......
...@@ -107,7 +107,6 @@ ...@@ -107,7 +107,6 @@
#import "ios/chrome/browser/ui/infobars/infobar_feature.h" #import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/ui/infobars/infobar_positioner.h" #import "ios/chrome/browser/ui/infobars/infobar_positioner.h"
#include "ios/chrome/browser/ui/location_bar/location_bar_model_delegate_ios.h" #include "ios/chrome/browser/ui/location_bar/location_bar_model_delegate_ios.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_notification_names.h"
#import "ios/chrome/browser/ui/main_content/main_content_ui.h" #import "ios/chrome/browser/ui/main_content/main_content_ui.h"
#import "ios/chrome/browser/ui/main_content/main_content_ui_broadcasting_util.h" #import "ios/chrome/browser/ui/main_content/main_content_ui_broadcasting_util.h"
#import "ios/chrome/browser/ui/main_content/main_content_ui_state.h" #import "ios/chrome/browser/ui/main_content/main_content_ui_state.h"
...@@ -3863,9 +3862,11 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3863,9 +3862,11 @@ NSString* const kBrowserViewControllerSnackbarCategory =
#pragma mark - ToolbarCoordinatorDelegate (Public) #pragma mark - ToolbarCoordinatorDelegate (Public)
- (void)locationBarDidBecomeFirstResponder { - (void)locationBarDidBecomeFirstResponder {
[[NSNotificationCenter defaultCenter] if (self.isNTPActiveForCurrentWebState) {
postNotificationName:kLocationBarBecomesFirstResponderNotification NewTabPageCoordinator* coordinator =
object:nil]; _ntpCoordinatorsForWebStates[self.currentWebState];
[coordinator locationBarDidBecomeFirstResponder];
}
[self.sideSwipeController setEnabled:NO]; [self.sideSwipeController setEnabled:NO];
if (!IsVisibleURLNewTabPage(self.currentWebState)) { if (!IsVisibleURLNewTabPage(self.currentWebState)) {
...@@ -3887,9 +3888,12 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3887,9 +3888,12 @@ NSString* const kBrowserViewControllerSnackbarCategory =
- (void)locationBarDidResignFirstResponder { - (void)locationBarDidResignFirstResponder {
[self.sideSwipeController setEnabled:YES]; [self.sideSwipeController setEnabled:YES];
[[NSNotificationCenter defaultCenter]
postNotificationName:kLocationBarResignsFirstResponderNotification if (self.isNTPActiveForCurrentWebState) {
object:nil]; NewTabPageCoordinator* coordinator =
_ntpCoordinatorsForWebStates[self.currentWebState];
[coordinator locationBarDidResignFirstResponder];
}
[UIView animateWithDuration:0.3 [UIView animateWithDuration:0.3
animations:^{ animations:^{
[self.typingShield setAlpha:0.0]; [self.typingShield setAlpha:0.0];
......
...@@ -62,7 +62,6 @@ source_set("content_suggestions") { ...@@ -62,7 +62,6 @@ source_set("content_suggestions") {
"//ios/chrome/browser/ui/content_suggestions/identifier", "//ios/chrome/browser/ui/content_suggestions/identifier",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/favicon", "//ios/chrome/browser/ui/favicon",
"//ios/chrome/browser/ui/location_bar:notifications",
"//ios/chrome/browser/ui/ntp", "//ios/chrome/browser/ui/ntp",
"//ios/chrome/browser/ui/ntp:ntp_internal", "//ios/chrome/browser/ui/ntp:ntp_internal",
"//ios/chrome/browser/ui/overscroll_actions", "//ios/chrome/browser/ui/overscroll_actions",
...@@ -218,7 +217,6 @@ source_set("unit_tests") { ...@@ -218,7 +217,6 @@ source_set("unit_tests") {
"//ios/chrome/browser/ui/content_suggestions/cells", "//ios/chrome/browser/ui/content_suggestions/cells",
"//ios/chrome/browser/ui/content_suggestions/cells:cells_ui", "//ios/chrome/browser/ui/content_suggestions/cells:cells_ui",
"//ios/chrome/browser/ui/content_suggestions/identifier", "//ios/chrome/browser/ui/content_suggestions/identifier",
"//ios/chrome/browser/ui/location_bar:notifications",
"//ios/chrome/browser/ui/toolbar/test", "//ios/chrome/browser/ui/toolbar/test",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/url_loading", "//ios/chrome/browser/url_loading",
......
...@@ -57,6 +57,12 @@ class WebState; ...@@ -57,6 +57,12 @@ class WebState;
// Reloads the suggestions. // Reloads the suggestions.
- (void)reload; - (void)reload;
// The location bar has lost focus.
- (void)locationBarDidResignFirstResponder;
// Tell location bar has taken focus.
- (void)locationBarDidBecomeFirstResponder;
@end @end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_COORDINATOR_H_
...@@ -313,4 +313,11 @@ ...@@ -313,4 +313,11 @@
[self.contentSuggestionsMediator.dataSink reloadAllData]; [self.contentSuggestionsMediator.dataSink reloadAllData];
} }
- (void)locationBarDidBecomeFirstResponder {
[self.NTPMediator locationBarDidBecomeFirstResponder];
}
- (void)locationBarDidResignFirstResponder {
[self.NTPMediator locationBarDidResignFirstResponder];
}
@end @end
...@@ -85,6 +85,12 @@ class UrlLoadingService; ...@@ -85,6 +85,12 @@ class UrlLoadingService;
// Cleans the mediator. // Cleans the mediator.
- (void)shutdown; - (void)shutdown;
// The location bar has lost focus.
- (void)locationBarDidResignFirstResponder;
// Tell location bar has taken focus.
- (void)locationBarDidBecomeFirstResponder;
@end @end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_NTP_HOME_MEDIATOR_H_ #endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_NTP_HOME_MEDIATOR_H_
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_consumer.h" #import "ios/chrome/browser/ui/content_suggestions/ntp_home_consumer.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_metrics.h" #import "ios/chrome/browser/ui/content_suggestions/ntp_home_metrics.h"
#import "ios/chrome/browser/ui/content_suggestions/user_account_image_update_delegate.h" #import "ios/chrome/browser/ui/content_suggestions/user_account_image_update_delegate.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_notification_names.h"
#include "ios/chrome/browser/ui/ntp/metrics.h" #include "ios/chrome/browser/ui/ntp/metrics.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h" #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h"
#import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h" #import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h"
...@@ -140,21 +139,9 @@ const char kNTPHelpURL[] = ...@@ -140,21 +139,9 @@ const char kNTPHelpURL[] =
self.templateURLService->Load(); self.templateURLService->Load();
[self searchEngineChanged]; [self searchEngineChanged];
// Set up notifications;
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self.consumer
selector:@selector(locationBarBecomesFirstResponder)
name:kLocationBarBecomesFirstResponderNotification
object:nil];
[defaultCenter addObserver:self.consumer
selector:@selector(locationBarResignsFirstResponder)
name:kLocationBarResignsFirstResponderNotification
object:nil];
} }
- (void)shutdown { - (void)shutdown {
[[NSNotificationCenter defaultCenter] removeObserver:self.consumer];
_searchEngineObserver.reset(); _searchEngineObserver.reset();
DCHECK(_webStateObserver); DCHECK(_webStateObserver);
if (_webState) { if (_webState) {
...@@ -164,6 +151,14 @@ const char kNTPHelpURL[] = ...@@ -164,6 +151,14 @@ const char kNTPHelpURL[] =
} }
} }
- (void)locationBarDidBecomeFirstResponder {
[self.consumer locationBarBecomesFirstResponder];
}
- (void)locationBarDidResignFirstResponder {
[self.consumer locationBarResignsFirstResponder];
}
#pragma mark - Properties. #pragma mark - Properties.
- (void)setWebState:(web::WebState*)webState { - (void)setWebState:(web::WebState*)webState {
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h" #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h" #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h"
#import "ios/chrome/browser/ui/content_suggestions/ntp_home_consumer.h" #import "ios/chrome/browser/ui/content_suggestions/ntp_home_consumer.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_notification_names.h"
#import "ios/chrome/browser/ui/toolbar/test/toolbar_test_navigation_manager.h" #import "ios/chrome/browser/ui/toolbar/test/toolbar_test_navigation_manager.h"
#include "ios/chrome/browser/url_loading/test_url_loading_service.h" #include "ios/chrome/browser/url_loading/test_url_loading_service.h"
#include "ios/chrome/browser/url_loading/url_loading_params.h" #include "ios/chrome/browser/url_loading/url_loading_params.h"
...@@ -134,9 +133,7 @@ TEST_F(NTPHomeMediatorTest, TestConsumerNotificationFocus) { ...@@ -134,9 +133,7 @@ TEST_F(NTPHomeMediatorTest, TestConsumerNotificationFocus) {
OCMExpect([consumer_ locationBarBecomesFirstResponder]); OCMExpect([consumer_ locationBarBecomesFirstResponder]);
// Action. // Action.
[[NSNotificationCenter defaultCenter] [mediator_ locationBarDidBecomeFirstResponder];
postNotificationName:kLocationBarBecomesFirstResponderNotification
object:nil];
// Test. // Test.
EXPECT_OCMOCK_VERIFY(consumer_); EXPECT_OCMOCK_VERIFY(consumer_);
...@@ -150,9 +147,7 @@ TEST_F(NTPHomeMediatorTest, TestConsumerNotificationUnfocus) { ...@@ -150,9 +147,7 @@ TEST_F(NTPHomeMediatorTest, TestConsumerNotificationUnfocus) {
OCMExpect([consumer_ locationBarResignsFirstResponder]); OCMExpect([consumer_ locationBarResignsFirstResponder]);
// Action. // Action.
[[NSNotificationCenter defaultCenter] [mediator_ locationBarDidResignFirstResponder];
postNotificationName:kLocationBarResignsFirstResponderNotification
object:nil];
// Test. // Test.
EXPECT_OCMOCK_VERIFY(consumer_); EXPECT_OCMOCK_VERIFY(consumer_);
......
...@@ -132,15 +132,6 @@ source_set("constants") { ...@@ -132,15 +132,6 @@ source_set("constants") {
] ]
} }
# TODO(crbug.com/778008): Remove this target.
source_set("notifications") {
sources = [
"location_bar_notification_names.h",
"location_bar_notification_names.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("unit_tests") { source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_NOTIFICATION_NAMES_H_
#define IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_NOTIFICATION_NAMES_H_
#import <Foundation/Foundation.h>
// Notification sent when the location bar becomes first responder. In UI
// Refresh, it is not repeatedly sent if the omnibox is refocused while the
// popup is still open.
extern NSString* const kLocationBarBecomesFirstResponderNotification;
// Notification sent when the location bar resigns first responder. Not sent
// when the omnibox resigns first responder while the popup is still open (i.e.
// when the popup is scrolled).
extern NSString* const kLocationBarResignsFirstResponderNotification;
#endif // IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_NOTIFICATION_NAMES_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/location_bar/location_bar_notification_names.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* const kLocationBarBecomesFirstResponderNotification =
@"kLocationBarBecomesFirstResponderNotification";
NSString* const kLocationBarResignsFirstResponderNotification =
@"kLocationBarResignsFirstResponderNotification";
...@@ -103,7 +103,6 @@ source_set("ntp_internal") { ...@@ -103,7 +103,6 @@ source_set("ntp_internal") {
"//ios/chrome/browser/ui/content_suggestions/cells", "//ios/chrome/browser/ui/content_suggestions/cells",
"//ios/chrome/browser/ui/context_menu", "//ios/chrome/browser/ui/context_menu",
"//ios/chrome/browser/ui/favicon", "//ios/chrome/browser/ui/favicon",
"//ios/chrome/browser/ui/location_bar:notifications",
"//ios/chrome/browser/ui/overscroll_actions", "//ios/chrome/browser/ui/overscroll_actions",
"//ios/chrome/browser/ui/toolbar/buttons", "//ios/chrome/browser/ui/toolbar/buttons",
"//ios/chrome/browser/ui/toolbar/public", "//ios/chrome/browser/ui/toolbar/public",
......
...@@ -61,6 +61,11 @@ class WebState; ...@@ -61,6 +61,11 @@ class WebState;
// Reloads the content of the NewTabPage. // Reloads the content of the NewTabPage.
- (void)reload; - (void)reload;
// The location bar has lost focus.
- (void)locationBarDidResignFirstResponder;
// Tell location bar has taken focus.
- (void)locationBarDidBecomeFirstResponder;
@end @end
#endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_COORDINATOR_H_
...@@ -114,6 +114,13 @@ ...@@ -114,6 +114,13 @@
[self.contentSuggestionsCoordinator reload]; [self.contentSuggestionsCoordinator reload];
} }
- (void)locationBarDidBecomeFirstResponder {
[self.contentSuggestionsCoordinator locationBarDidBecomeFirstResponder];
}
- (void)locationBarDidResignFirstResponder {
[self.contentSuggestionsCoordinator locationBarDidResignFirstResponder];
}
#pragma mark - LogoAnimationControllerOwnerOwner #pragma mark - LogoAnimationControllerOwnerOwner
- (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
......
...@@ -27,7 +27,6 @@ source_set("overscroll_actions") { ...@@ -27,7 +27,6 @@ source_set("overscroll_actions") {
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant", "//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/fullscreen", "//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/browser/ui/fullscreen:feature_flags", "//ios/chrome/browser/ui/fullscreen:feature_flags",
"//ios/chrome/browser/ui/location_bar:notifications",
"//ios/chrome/browser/ui/page_info:constants", "//ios/chrome/browser/ui/page_info:constants",
"//ios/chrome/browser/ui/side_swipe", "//ios/chrome/browser/ui/side_swipe",
"//ios/chrome/browser/ui/toolbar/public", "//ios/chrome/browser/ui/toolbar/public",
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h"
#import "ios/chrome/browser/ui/fullscreen/scoped_fullscreen_disabler.h" #import "ios/chrome/browser/ui/fullscreen/scoped_fullscreen_disabler.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_notification_names.h"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_gesture_recognizer.h" #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_gesture_recognizer.h"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h" #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_view.h"
#import "ios/chrome/browser/ui/page_info/page_info_constants.h" #import "ios/chrome/browser/ui/page_info/page_info_constants.h"
...@@ -297,8 +296,6 @@ NSString* const kOverscrollActionsDidEnd = @"OverscrollActionsDidStop"; ...@@ -297,8 +296,6 @@ NSString* const kOverscrollActionsDidEnd = @"OverscrollActionsDidStop";
UIKeyboardWillHideNotification : UIKeyboardWillShowNotification, UIKeyboardWillHideNotification : UIKeyboardWillShowNotification,
kVoiceSearchWillHideNotification : kVoiceSearchWillShowNotification, kVoiceSearchWillHideNotification : kVoiceSearchWillShowNotification,
kPageInfoWillHideNotification : kPageInfoWillShowNotification, kPageInfoWillHideNotification : kPageInfoWillShowNotification,
kLocationBarResignsFirstResponderNotification :
kLocationBarBecomesFirstResponderNotification,
kSideSwipeDidStopNotification : kSideSwipeWillStartNotification kSideSwipeDidStopNotification : kSideSwipeWillStartNotification
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment