Commit e4afa8b5 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Don't remove the old content view if re-displaying it.

BrowserContainerView's |-displayContentView:| should have no effect if
called twice with the same argument, but its current implementation
changes the view hierarchy in this case.

This CL is a partial solution to fix a specific issue with the voice
search button NamedGuide to minimize risk.

Bug: 826093
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ia2d58883df057df2ad430ecdbc7ccdf28f02a4cd
Reviewed-on: https://chromium-review.googlesource.com/981609
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546245}
parent cd477bac
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#import "ios/chrome/browser/ui/browser_container_view.h" #import "ios/chrome/browser/ui/browser_container_view.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#include "base/logging.h" #include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -21,13 +23,28 @@ ...@@ -21,13 +23,28 @@
} }
- (void)displayContentView:(UIView*)contentView { - (void)displayContentView:(UIView*)contentView {
if (_contentView == contentView) {
// When voice search is launched from the NTP, the voice search button
// NamedGuide is constrained to a subview of |_contentView|. If this
// occurs, removing |_contentView| from the hierarchy below will deactivate
// the constraints. The check against the voice search button guide is a
// temporary workaround in order to minimize unintended side effects from
// this change; this function should be a no-op when |_contentView| ==
// |contentView|, regardless of the NamedGuide constraints.
// TODO(crbug.com/826093): Remove NamedGuide check and simply early return.
NamedGuide* voiceSearchGuide =
[NamedGuide guideWithName:kVoiceSearchButtonGuide view:self];
UIView* voiceSearchButton = voiceSearchGuide.constrainedView;
if ([voiceSearchButton isDescendantOfView:_contentView])
return;
}
DCHECK(![_contentView superview] || [_contentView superview] == self); DCHECK(![_contentView superview] || [_contentView superview] == self);
[_contentView removeFromSuperview]; [_contentView removeFromSuperview];
_contentView = contentView; _contentView = contentView;
if (contentView) { if (contentView)
[self addSubview:contentView]; [self addSubview:contentView];
}
} }
@end @end
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