Commit d21e3816 authored by stkhapugin@chromium.org's avatar stkhapugin@chromium.org Committed by Commit Bot

Defocus the omnibox when switching tabs.

CL 905511 introduced a bug where previously BVC was defocusing the
omnibox by sending selectedTabChanged to the toolbar, but this was
broken.

Since the location bar now directly observes the webstate with its
mediator, use this to defocus omnibox when the webstate changes.

Bug: 813944
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ibc67faaae115032e0a3c6e6b5e3879d7e52f8f0f
Reviewed-on: https://chromium-review.googlesource.com/960663Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542817}
parent 40109c91
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
// text and the cursor position. // text and the cursor position.
- (void)updateOmniboxState; - (void)updateOmniboxState;
// Notifies consumer to defocus the omnibox (for example on tab change).
- (void)defocusOmnibox;
@end @end
#endif // IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_CONSUMER_H_ #endif // IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_CONSUMER_H_
...@@ -142,16 +142,6 @@ const int kLocationAuthorizationStatusCount = 4; ...@@ -142,16 +142,6 @@ const int kLocationAuthorizationStatusCount = 4;
return self.omniboxPopupCoordinator.hasResults; return self.omniboxPopupCoordinator.hasResults;
} }
#pragma mark - LocationBarConsumer
- (void)updateOmniboxState {
if (!_locationBarController)
return;
_locationBarController->SetShouldShowHintText(
[self.delegate shouldDisplayHintText]);
_locationBarController->OnToolbarUpdated();
}
- (BOOL)showingOmniboxPopup { - (BOOL)showingOmniboxPopup {
OmniboxViewIOS* omniboxViewIOS = static_cast<OmniboxViewIOS*>( OmniboxViewIOS* omniboxViewIOS = static_cast<OmniboxViewIOS*>(
_locationBarController.get()->GetLocationEntry()); _locationBarController.get()->GetLocationEntry());
...@@ -178,6 +168,20 @@ const int kLocationAuthorizationStatusCount = 4; ...@@ -178,6 +168,20 @@ const int kLocationAuthorizationStatusCount = 4;
[self.locationBarView addContractOmniboxAnimations:animator]; [self.locationBarView addContractOmniboxAnimations:animator];
} }
#pragma mark - LocationBarConsumer
- (void)updateOmniboxState {
if (!_locationBarController)
return;
_locationBarController->SetShouldShowHintText(
[self.delegate shouldDisplayHintText]);
_locationBarController->OnToolbarUpdated();
}
- (void)defocusOmnibox {
[self cancelOmniboxEdit];
}
#pragma mark - VoiceSearchControllerDelegate #pragma mark - VoiceSearchControllerDelegate
- (void)receiveVoiceSearchResult:(NSString*)result { - (void)receiveVoiceSearchResult:(NSString*)result {
......
...@@ -115,6 +115,7 @@ ...@@ -115,6 +115,7 @@
reason:(int)reason { reason:(int)reason {
DCHECK_EQ(_webStateList, webStateList); DCHECK_EQ(_webStateList, webStateList);
self.webState = newWebState; self.webState = newWebState;
[self.consumer defocusOmnibox];
} }
#pragma mark - Setters #pragma mark - Setters
......
...@@ -213,3 +213,15 @@ TEST_F(LocationBarMediatorTest, TestDidChangeVisibleSecurityState) { ...@@ -213,3 +213,15 @@ TEST_F(LocationBarMediatorTest, TestDidChangeVisibleSecurityState) {
EXPECT_OCMOCK_VERIFY(consumer_); EXPECT_OCMOCK_VERIFY(consumer_);
} }
// Test the omnibox is defocused when the active webstate is changed.
TEST_F(LocationBarMediatorTest, TestChangeActiveWebState) {
mediator_.webStateList = web_state_list_.get();
SetUpActiveWebState();
mediator_.consumer = consumer_;
OCMExpect([consumer_ defocusOmnibox]);
web_state_list_->ActivateWebStateAt(1);
EXPECT_OCMOCK_VERIFY(consumer_);
}
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