Commit 7bf9d04f authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Unfocus omnibox when recreating NTP

This CL unfocusing the omnibox when the NTP is created. This is needed
as the NTP is re-created when the browsing data are cleared. This can
happen while the omnibox is focused on multiwindow.
Unfocusing the omnibox ensure that the NTP state (i.e. scrolled down)
is matching the omnibox state.

Bug: 1139191
Change-Id: I07d050bc1c2d90178bf80786150fd2cbc1d4e4f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550044
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831000}
parent fca509a9
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h" #import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/omnibox_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h" #import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#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_action_handler.h" #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_action_handler.h"
...@@ -138,6 +139,12 @@ ...@@ -138,6 +139,12 @@
_visible = YES; _visible = YES;
// Make sure that the omnibox is unfocused to prevent having it visually
// focused while the NTP is just created (with the fakebox visible).
id<OmniboxCommands> omniboxCommandHandler =
HandlerForProtocol(self.browser->GetCommandDispatcher(), OmniboxCommands);
[omniboxCommandHandler cancelOmniboxEdit];
self.authService = AuthenticationServiceFactory::GetForBrowserState( self.authService = AuthenticationServiceFactory::GetForBrowserState(
self.browser->GetBrowserState()); self.browser->GetBrowserState());
self.authService->WaitUntilCacheIsPopulated(); self.authService->WaitUntilCacheIsPopulated();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#import "ios/chrome/browser/signin/authentication_service_factory.h" #import "ios/chrome/browser/signin/authentication_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service_fake.h" #import "ios/chrome/browser/signin/authentication_service_fake.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/omnibox_commands.h"
#import "ios/chrome/browser/ui/commands/snackbar_commands.h" #import "ios/chrome/browser/ui/commands/snackbar_commands.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/main/scene_state.h" #import "ios/chrome/browser/ui/main/scene_state.h"
...@@ -90,8 +91,11 @@ class NewTabPageCoordinatorTest : public PlatformTest { ...@@ -90,8 +91,11 @@ class NewTabPageCoordinatorTest : public PlatformTest {
// Tests that the coordinator vends a content suggestions VC on the record. // Tests that the coordinator vends a content suggestions VC on the record.
TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) { TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) {
CreateCoordinator(/*off_the_record=*/false); CreateCoordinator(/*off_the_record=*/false);
id snackbarCommandsHandlerMock = id omniboxCommandsHandlerMock = OCMProtocolMock(@protocol(OmniboxCommands));
[OCMockObject mockForProtocol:@protocol(SnackbarCommands)]; id snackbarCommandsHandlerMock = OCMProtocolMock(@protocol(SnackbarCommands));
[browser_.get()->GetCommandDispatcher()
startDispatchingToTarget:omniboxCommandsHandlerMock
forProtocol:@protocol(OmniboxCommands)];
[browser_.get()->GetCommandDispatcher() [browser_.get()->GetCommandDispatcher()
startDispatchingToTarget:snackbarCommandsHandlerMock startDispatchingToTarget:snackbarCommandsHandlerMock
forProtocol:@protocol(SnackbarCommands)]; forProtocol:@protocol(SnackbarCommands)];
......
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