Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 2196203002: [Mac] The infobar's top arrow should be hidden while the omnibox popup is shown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crasher Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <numeric> 8 #include <numeric>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/mac/bundle_locations.h" 12 #include "base/mac/bundle_locations.h"
13 #import "base/mac/foundation_util.h" 13 #import "base/mac/foundation_util.h"
14 #include "base/mac/mac_util.h" 14 #include "base/mac/mac_util.h"
15 #import "base/mac/sdk_forward_declarations.h" 15 #import "base/mac/sdk_forward_declarations.h"
16 #include "base/scoped_observer.h"
16 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/app/chrome_command_ids.h" // IDC_* 19 #include "chrome/app/chrome_command_ids.h" // IDC_*
19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 20 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
20 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" 21 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
21 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/browser_shutdown.h" 23 #include "chrome/browser/browser_shutdown.h"
23 #include "chrome/browser/devtools/devtools_window.h" 24 #include "chrome/browser/devtools/devtools_window.h"
24 #include "chrome/browser/extensions/extension_commands_global_registry.h" 25 #include "chrome/browser/extensions/extension_commands_global_registry.h"
25 #include "chrome/browser/permissions/permission_request_manager.h" 26 #include "chrome/browser/permissions/permission_request_manager.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 58 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
58 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 59 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
59 #import "chrome/browser/ui/cocoa/framed_browser_window.h" 60 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
60 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h" 61 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller.h"
61 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c ontroller.h" 62 #import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_c ontroller.h"
62 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h" 63 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h"
63 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 64 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
64 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 65 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
65 #include "chrome/browser/ui/cocoa/l10n_util.h" 66 #include "chrome/browser/ui/cocoa/l10n_util.h"
66 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 67 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
68 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
67 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h" 69 #include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h"
68 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" 70 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h"
69 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" 71 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
70 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" 72 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h"
71 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" 73 #import "chrome/browser/ui/cocoa/status_bubble_mac.h"
72 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" 74 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
73 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" 75 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
74 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 76 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
75 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 77 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
76 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 78 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
77 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 79 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
78 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" 80 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h"
79 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 81 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
80 #include "chrome/browser/ui/location_bar/location_bar.h" 82 #include "chrome/browser/ui/location_bar/location_bar.h"
81 #include "chrome/browser/ui/tabs/tab_strip_model.h" 83 #include "chrome/browser/ui/tabs/tab_strip_model.h"
82 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 84 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
83 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" 85 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
84 #include "chrome/browser/ui/window_sizer/window_sizer.h" 86 #include "chrome/browser/ui/window_sizer/window_sizer.h"
85 #include "chrome/common/chrome_switches.h" 87 #include "chrome/common/chrome_switches.h"
86 #include "chrome/common/extensions/command.h" 88 #include "chrome/common/extensions/command.h"
87 #include "chrome/common/pref_names.h" 89 #include "chrome/common/pref_names.h"
88 #include "components/bookmarks/browser/bookmark_model.h" 90 #include "components/bookmarks/browser/bookmark_model.h"
89 #include "components/bookmarks/managed/managed_bookmark_service.h" 91 #include "components/bookmarks/managed/managed_bookmark_service.h"
92 #include "components/omnibox/browser/omnibox_edit_model.h"
93 #include "components/omnibox/browser/omnibox_popup_model.h"
94 #include "components/omnibox/browser/omnibox_popup_model_observer.h"
90 #include "components/signin/core/common/profile_management_switches.h" 95 #include "components/signin/core/common/profile_management_switches.h"
91 #include "components/translate/core/browser/translate_manager.h" 96 #include "components/translate/core/browser/translate_manager.h"
92 #include "components/translate/core/browser/translate_ui_delegate.h" 97 #include "components/translate/core/browser/translate_ui_delegate.h"
93 #include "components/web_modal/web_contents_modal_dialog_manager.h" 98 #include "components/web_modal/web_contents_modal_dialog_manager.h"
94 #include "content/public/browser/render_view_host.h" 99 #include "content/public/browser/render_view_host.h"
95 #include "content/public/browser/render_widget_host.h" 100 #include "content/public/browser/render_widget_host.h"
96 #include "content/public/browser/render_widget_host_view.h" 101 #include "content/public/browser/render_widget_host_view.h"
97 #include "content/public/browser/web_contents.h" 102 #include "content/public/browser/web_contents.h"
98 #import "ui/base/cocoa/cocoa_base_utils.h" 103 #import "ui/base/cocoa/cocoa_base_utils.h"
99 #import "ui/base/cocoa/nsview_additions.h" 104 #import "ui/base/cocoa/nsview_additions.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // set a flag, and constrain any resize by the allowed amounts. On further 183 // set a flag, and constrain any resize by the allowed amounts. On further
179 // shrinks, we check the flag (since the size/position of the window will no 184 // shrinks, we check the flag (since the size/position of the window will no
180 // longer indicate that the window is shrinking from an apparent zoomed state) 185 // longer indicate that the window is shrinking from an apparent zoomed state)
181 // and if it's set we continue to constrain the resize. 186 // and if it's set we continue to constrain the resize.
182 187
183 using content::RenderWidgetHostView; 188 using content::RenderWidgetHostView;
184 using content::WebContents; 189 using content::WebContents;
185 190
186 namespace { 191 namespace {
187 192
193 // This class shows or hides the top arrow of the infobar in accordance with the
194 // visibility of the omnibox popup. It hides the top arrow when the omnibox
195 // popup is shown, and vice versa.
196 class OmniboxPopupModelObserverBridge final : public OmniboxPopupModelObserver {
197 public:
198 explicit OmniboxPopupModelObserverBridge(BrowserWindowController* controller)
199 : controller_(controller),
200 omnibox_popup_model_([controller_ locationBarBridge]
201 ->GetOmniboxView()
202 ->model()
203 ->popup_model()),
204 omnibox_popup_model_observer_(this) {
205 DCHECK(omnibox_popup_model_);
206 omnibox_popup_model_observer_.Add(omnibox_popup_model_);
207 }
208
209 void OnOmniboxPopupShownOrHidden() override {
210 int max_top_arrow_height = 0;
211 if (!omnibox_popup_model_->IsOpen()) {
212 base::scoped_nsobject<BrowserWindowLayout> layout(
213 [[BrowserWindowLayout alloc] init]);
214 [controller_ updateLayoutParameters:layout];
215 max_top_arrow_height = [layout computeLayout].infoBarMaxTopArrowHeight;
216 }
217 [[controller_ infoBarContainerController]
218 setMaxTopArrowHeight:max_top_arrow_height];
219 }
220
221 private:
222 BrowserWindowController* controller_;
223 OmniboxPopupModel* omnibox_popup_model_;
224 ScopedObserver<OmniboxPopupModel, OmniboxPopupModelObserver>
225 omnibox_popup_model_observer_;
226
227 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupModelObserverBridge);
228 };
229
188 void SetUpBrowserWindowCommandHandler(NSWindow* window) { 230 void SetUpBrowserWindowCommandHandler(NSWindow* window) {
189 // Make the window handle browser window commands. 231 // Make the window handle browser window commands.
190 [base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window) 232 [base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window)
191 setCommandHandler:[[[BrowserWindowCommandHandler alloc] init] 233 setCommandHandler:[[[BrowserWindowCommandHandler alloc] init]
192 autorelease]]; 234 autorelease]];
193 } 235 }
194 236
195 // Returns true if the Tab Detaching in Fullscreen is enabled. It's enabled by 237 // Returns true if the Tab Detaching in Fullscreen is enabled. It's enabled by
196 // default. 238 // default.
197 bool IsTabDetachingInFullscreenEnabled() { 239 bool IsTabDetachingInFullscreenEnabled() {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // on the window bounds to determine whether to show buttons or not. 424 // on the window bounds to determine whether to show buttons or not.
383 if ([self hasToolbar]) // Do not create the buttons in popups. 425 if ([self hasToolbar]) // Do not create the buttons in popups.
384 [toolbarController_ createBrowserActionButtons]; 426 [toolbarController_ createBrowserActionButtons];
385 427
386 extensionKeybindingRegistry_.reset( 428 extensionKeybindingRegistry_.reset(
387 new ExtensionKeybindingRegistryCocoa(browser_->profile(), 429 new ExtensionKeybindingRegistryCocoa(browser_->profile(),
388 [self window], 430 [self window],
389 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, 431 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS,
390 windowShim_.get())); 432 windowShim_.get()));
391 433
434 omniboxPopupModelObserverBridge_.reset(
435 new OmniboxPopupModelObserverBridge(self));
Peter Kasting 2017/04/15 17:37:03 Nit: Prefer = base::MakeUnique<> over reset(new ..
436
392 blockLayoutSubviews_ = NO; 437 blockLayoutSubviews_ = NO;
393 438
394 // We are done initializing now. 439 // We are done initializing now.
395 initializing_ = NO; 440 initializing_ = NO;
396 } 441 }
397 return self; 442 return self;
398 } 443 }
399 444
400 - (void)dealloc { 445 - (void)dealloc {
401 browser_->tab_strip_model()->CloseAllTabs(); 446 browser_->tab_strip_model()->CloseAllTabs();
402 447
403 // Explicitly release |fullscreenToolbarController_| here, as it may call 448 // Explicitly release |fullscreenToolbarController_| here, as it may call
404 // back to this BWC in |-dealloc|. 449 // back to this BWC in |-dealloc|.
405 [fullscreenToolbarController_ exitFullscreenMode]; 450 [fullscreenToolbarController_ exitFullscreenMode];
406 fullscreenToolbarController_.reset(); 451 fullscreenToolbarController_.reset();
407 452
408 // Explicitly release |fullscreenTransition_| here since it may call back to 453 // Explicitly release |fullscreenTransition_| here since it may call back to
409 // this BWC in |-dealloc|. Reset the fullscreen variables. 454 // this BWC in |-dealloc|. Reset the fullscreen variables.
410 if (fullscreenTransition_) { 455 if (fullscreenTransition_) {
411 [fullscreenTransition_ browserWillBeDestroyed]; 456 [fullscreenTransition_ browserWillBeDestroyed];
412 [self resetCustomAppKitFullscreenVariables]; 457 [self resetCustomAppKitFullscreenVariables];
413 } 458 }
414 459
415 // Under certain testing configurations we may not actually own the browser. 460 // Under certain testing configurations we may not actually own the browser.
416 if (ownsBrowser_ == NO) 461 if (ownsBrowser_ == NO)
417 ignore_result(browser_.release()); 462 ignore_result(browser_.release());
418 463
419 [[NSNotificationCenter defaultCenter] removeObserver:self]; 464 [[NSNotificationCenter defaultCenter] removeObserver:self];
420 465
466 omniboxPopupModelObserverBridge_.reset();
Peter Kasting 2017/04/15 17:37:02 Nit: Add comment about why this has to be reset he
467
421 // Inform reference counted objects that the Browser will be destroyed. This 468 // Inform reference counted objects that the Browser will be destroyed. This
422 // ensures they invalidate their weak Browser* to prevent use-after-free. 469 // ensures they invalidate their weak Browser* to prevent use-after-free.
423 // These may outlive the Browser if they are retained by something else. For 470 // These may outlive the Browser if they are retained by something else. For
424 // example, since 10.10, the Nib loader internally creates an NSDictionary 471 // example, since 10.10, the Nib loader internally creates an NSDictionary
425 // that retains NSViewControllers and is autoreleased, so there is no way to 472 // that retains NSViewControllers and is autoreleased, so there is no way to
426 // guarantee that the [super dealloc] call below will also call dealloc on the 473 // guarantee that the [super dealloc] call below will also call dealloc on the
427 // controllers. 474 // controllers.
428 [toolbarController_ browserWillBeDestroyed]; 475 [toolbarController_ browserWillBeDestroyed];
429 [tabStripController_ browserWillBeDestroyed]; 476 [tabStripController_ browserWillBeDestroyed];
430 [findBarCocoaController_ browserWillBeDestroyed]; 477 [findBarCocoaController_ browserWillBeDestroyed];
(...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 2080
2034 - (NSRect)savedRegularWindowFrame { 2081 - (NSRect)savedRegularWindowFrame {
2035 return savedRegularWindowFrame_; 2082 return savedRegularWindowFrame_;
2036 } 2083 }
2037 2084
2038 - (BOOL)isFullscreenTransitionInProgress { 2085 - (BOOL)isFullscreenTransitionInProgress {
2039 return enteringAppKitFullscreen_ || exitingAppKitFullscreen_; 2086 return enteringAppKitFullscreen_ || exitingAppKitFullscreen_;
2040 } 2087 }
2041 2088
2042 @end // @implementation BrowserWindowController(WindowType) 2089 @end // @implementation BrowserWindowController(WindowType)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698