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

[iOS] Check for toolbar frame updates after each layout pass.

When safe area inset usage is enabled, the constraint system bypasses
|-setFrame:| when updating the view upon rotation, so the omnibox's and
buttons' opacities were not updated properly.  This CL changes the
delegate protocol to wait for layout events rather than frame setting.

Bug: 778750
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I0cbd3bf66f0c53a156da269ed510fcad71ed87ec
Reviewed-on: https://chromium-review.googlesource.com/745723
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512874}
parent 3a08bf90
...@@ -15,7 +15,6 @@ source_set("toolbar") { ...@@ -15,7 +15,6 @@ source_set("toolbar") {
"toolbar_controller.mm", "toolbar_controller.mm",
"toolbar_coordinator.h", "toolbar_coordinator.h",
"toolbar_coordinator.mm", "toolbar_coordinator.mm",
"toolbar_frame_delegate.h",
"toolbar_model_delegate_ios.h", "toolbar_model_delegate_ios.h",
"toolbar_model_delegate_ios.mm", "toolbar_model_delegate_ios.mm",
"toolbar_model_impl_ios.h", "toolbar_model_impl_ios.h",
...@@ -27,6 +26,7 @@ source_set("toolbar") { ...@@ -27,6 +26,7 @@ source_set("toolbar") {
"toolbar_tools_menu_button.mm", "toolbar_tools_menu_button.mm",
"toolbar_view.h", "toolbar_view.h",
"toolbar_view.mm", "toolbar_view.mm",
"toolbar_view_delegate.h",
"tools_menu_button_observer_bridge.h", "tools_menu_button_observer_bridge.h",
"tools_menu_button_observer_bridge.mm", "tools_menu_button_observer_bridge.mm",
"web_toolbar_controller.h", "web_toolbar_controller.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.
#ifndef IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_FRAME_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_FRAME_DELEGATE_H_
#import <Foundation/Foundation.h>
// Create a thin wrapper around UIImageView to catch frame change and window
// events.
@protocol ToolbarFrameDelegate<NSObject>
- (void)frameDidChangeFrame:(CGRect)newFrame fromFrame:(CGRect)oldFrame;
- (void)windowDidChange;
- (void)traitCollectionDidChange;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_FRAME_DELEGATE_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#import "ios/chrome/browser/ui/util/relaxed_bounds_constraints_hittest.h" #import "ios/chrome/browser/ui/util/relaxed_bounds_constraints_hittest.h"
@protocol ToolbarFrameDelegate; @protocol ToolbarViewDelegate;
@interface ToolbarView : UIView<RelaxedBoundsConstraintsHitTestSupport> @interface ToolbarView : UIView<RelaxedBoundsConstraintsHitTestSupport>
- (instancetype)initWithNibName:(NSString*)name - (instancetype)initWithNibName:(NSString*)name
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
- (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE; - (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE;
// The delegate used to handle frame changes and windows events. // The delegate used to handle frame changes and windows events.
@property(nonatomic, weak) id<ToolbarFrameDelegate> delegate; @property(nonatomic, weak) id<ToolbarViewDelegate> delegate;
// Records whether or not the toolbar is currently involved in a transition // Records whether or not the toolbar is currently involved in a transition
// animation. // animation.
@property(nonatomic, assign, getter=isAnimatingTransition) @property(nonatomic, assign, getter=isAnimatingTransition)
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#import "ios/chrome/browser/ui/toolbar/toolbar_view.h" #import "ios/chrome/browser/ui/toolbar/toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_base_feature.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_base_feature.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_frame_delegate.h" #import "ios/chrome/browser/ui/toolbar/toolbar_view_delegate.h"
@implementation ToolbarView @implementation ToolbarView
...@@ -57,10 +57,9 @@ ...@@ -57,10 +57,9 @@
return hitView; return hitView;
} }
- (void)setFrame:(CGRect)frame { - (void)layoutSubviews {
CGRect oldFrame = self.frame; [super layoutSubviews];
[super setFrame:frame]; [delegate_ toolbarDidLayout];
[delegate_ frameDidChangeFrame:frame fromFrame:oldFrame];
} }
- (void)didMoveToWindow { - (void)didMoveToWindow {
......
// 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_TOOLBAR_TOOLBAR_VIEW_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_VIEW_DELEGATE_H_
#import <Foundation/Foundation.h>
// A delegate protocol to pass UIView information about the toolbar.
// TODO(crbug.com/683793): Remove this protocol when toolbars are presented via
// UIViewControllers, as this can already be accomplished through that API.
@protocol ToolbarViewDelegate<NSObject>
// Called when the toolbar view performs a layout pass.
- (void)toolbarDidLayout;
// Called when the toolbar view is transferred to a new parent window.
- (void)windowDidChange;
// Called when the toolbar view's trait collection changes.
- (void)traitCollectionDidChange;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_VIEW_DELEGATE_H_
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
@protocol ApplicationCommands; @protocol ApplicationCommands;
@protocol BrowserCommands; @protocol BrowserCommands;
@class Tab; @class Tab;
@protocol ToolbarFrameDelegate;
@protocol UrlLoader; @protocol UrlLoader;
@protocol WebToolbarDelegate; @protocol WebToolbarDelegate;
......
...@@ -59,9 +59,9 @@ ...@@ -59,9 +59,9 @@
#import "ios/chrome/browser/ui/toolbar/public/toolbar_utils.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_utils.h"
#import "ios/chrome/browser/ui/toolbar/public/web_toolbar_controller_constants.h" #import "ios/chrome/browser/ui/toolbar/public/web_toolbar_controller_constants.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h" #import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_frame_delegate.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" #import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h"
#include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_view_delegate.h"
#import "ios/chrome/browser/ui/toolbar/web_toolbar_delegate.h" #import "ios/chrome/browser/ui/toolbar/web_toolbar_delegate.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
...@@ -102,7 +102,7 @@ using ios::material::TimingFunction; ...@@ -102,7 +102,7 @@ using ios::material::TimingFunction;
LocationBarDelegate, LocationBarDelegate,
OmniboxPopupPositioner, OmniboxPopupPositioner,
ToolbarAssistiveKeyboardDelegate, ToolbarAssistiveKeyboardDelegate,
ToolbarFrameDelegate> { ToolbarViewDelegate> {
// Top-level view for web content. // Top-level view for web content.
UIView* _webToolbar; UIView* _webToolbar;
UIButton* _backButton; UIButton* _backButton;
...@@ -140,6 +140,9 @@ using ios::material::TimingFunction; ...@@ -140,6 +140,9 @@ using ios::material::TimingFunction;
// reversed. // reversed.
ToolbarButtonMode _forwardButtonMode; ToolbarButtonMode _forwardButtonMode;
// Keeps track of the last known toolbar frame.
CGRect _lastKnownToolbarFrame;
// Keeps track of last known trait collection used by the subviews. // Keeps track of last known trait collection used by the subviews.
UITraitCollection* _lastKnownTraitCollection; UITraitCollection* _lastKnownTraitCollection;
...@@ -1201,12 +1204,14 @@ using ios::material::TimingFunction; ...@@ -1201,12 +1204,14 @@ using ios::material::TimingFunction;
} }
#pragma mark - #pragma mark -
#pragma mark ToolbarFrameDelegate methods. #pragma mark ToolbarViewDelegate methods.
- (void)frameDidChangeFrame:(CGRect)newFrame fromFrame:(CGRect)oldFrame { - (void)toolbarDidLayout {
if (oldFrame.origin.y == newFrame.origin.y) CGRect frame = self.view.frame;
if (CGRectEqualToRect(_lastKnownToolbarFrame, frame))
return; return;
[self updateToolbarAlphaForFrame:newFrame]; [self updateToolbarAlphaForFrame:frame];
_lastKnownToolbarFrame = frame;
} }
- (void)windowDidChange { - (void)windowDidChange {
......
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