Chromium Code Reviews| Index: chrome/browser/ui/cocoa/browser_window_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm |
| index 2fd4f20fa2362cd5b3c99df981d23eb4abb640b3..7c5d75a49b47511ebf422e22bab61fa401c77391 100644 |
| --- a/chrome/browser/ui/cocoa/browser_window_controller.mm |
| +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm |
| @@ -13,6 +13,7 @@ |
| #import "base/mac/foundation_util.h" |
| #include "base/mac/mac_util.h" |
| #import "base/mac/sdk_forward_declarations.h" |
| +#include "base/scoped_observer.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" // IDC_* |
| @@ -64,6 +65,7 @@ |
| #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| #include "chrome/browser/ui/cocoa/l10n_util.h" |
| #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| +#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" |
| #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" |
| #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" |
| @@ -87,6 +89,9 @@ |
| #include "chrome/common/pref_names.h" |
| #include "components/bookmarks/browser/bookmark_model.h" |
| #include "components/bookmarks/managed/managed_bookmark_service.h" |
| +#include "components/omnibox/browser/omnibox_edit_model.h" |
| +#include "components/omnibox/browser/omnibox_popup_model.h" |
| +#include "components/omnibox/browser/omnibox_popup_model_observer.h" |
| #include "components/signin/core/common/profile_management_switches.h" |
| #include "components/translate/core/browser/translate_manager.h" |
| #include "components/translate/core/browser/translate_ui_delegate.h" |
| @@ -185,6 +190,43 @@ |
| namespace { |
| +// This class shows or hides the top arrow of the infobar in accordance with the |
| +// visibility of the omnibox popup. It hides the top arrow when the omnibox |
| +// popup is shown, and vice versa. |
| +class OmniboxPopupModelObserverBridge final : public OmniboxPopupModelObserver { |
| + public: |
| + explicit OmniboxPopupModelObserverBridge(BrowserWindowController* controller) |
| + : controller_(controller), |
| + omnibox_popup_model_([controller_ locationBarBridge] |
| + ->GetOmniboxView() |
| + ->model() |
| + ->popup_model()), |
| + omnibox_popup_model_observer_(this) { |
| + DCHECK(omnibox_popup_model_); |
| + omnibox_popup_model_observer_.Add(omnibox_popup_model_); |
| + } |
| + |
| + void OnOmniboxPopupShownOrHidden() override { |
| + int max_top_arrow_height = 0; |
| + if (!omnibox_popup_model_->IsOpen()) { |
| + base::scoped_nsobject<BrowserWindowLayout> layout( |
| + [[BrowserWindowLayout alloc] init]); |
| + [controller_ updateLayoutParameters:layout]; |
| + max_top_arrow_height = [layout computeLayout].infoBarMaxTopArrowHeight; |
| + } |
| + [[controller_ infoBarContainerController] |
| + setMaxTopArrowHeight:max_top_arrow_height]; |
| + } |
| + |
| + private: |
| + BrowserWindowController* controller_; |
| + OmniboxPopupModel* omnibox_popup_model_; |
| + ScopedObserver<OmniboxPopupModel, OmniboxPopupModelObserver> |
| + omnibox_popup_model_observer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OmniboxPopupModelObserverBridge); |
| +}; |
| + |
| void SetUpBrowserWindowCommandHandler(NSWindow* window) { |
| // Make the window handle browser window commands. |
| [base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window) |
| @@ -389,6 +431,9 @@ new ExtensionKeybindingRegistryCocoa(browser_->profile(), |
| extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| windowShim_.get())); |
| + omniboxPopupModelObserverBridge_.reset( |
| + new OmniboxPopupModelObserverBridge(self)); |
|
Peter Kasting
2017/04/15 17:37:03
Nit: Prefer = base::MakeUnique<> over reset(new ..
|
| + |
| blockLayoutSubviews_ = NO; |
| // We are done initializing now. |
| @@ -418,6 +463,8 @@ - (void)dealloc { |
| [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| + omniboxPopupModelObserverBridge_.reset(); |
|
Peter Kasting
2017/04/15 17:37:02
Nit: Add comment about why this has to be reset he
|
| + |
| // Inform reference counted objects that the Browser will be destroyed. This |
| // ensures they invalidate their weak Browser* to prevent use-after-free. |
| // These may outlive the Browser if they are retained by something else. For |