OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #import "chrome/browser/ui/cocoa/event_utils.h" | 40 #import "chrome/browser/ui/cocoa/event_utils.h" |
41 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 41 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
42 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 42 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
43 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 43 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
44 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 44 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
45 #import "chrome/browser/ui/cocoa/fullscreen_window.h" | 45 #import "chrome/browser/ui/cocoa/fullscreen_window.h" |
46 #import "chrome/browser/ui/cocoa/image_utils.h" | 46 #import "chrome/browser/ui/cocoa/image_utils.h" |
47 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 47 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
48 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 48 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
49 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 49 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
50 #import "chrome/browser/ui/cocoa/sidebar_controller.h" | |
51 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 50 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
52 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" | 51 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" |
53 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 52 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
54 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 53 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
55 #import "chrome/browser/ui/cocoa/tabpose_window.h" | 54 #import "chrome/browser/ui/cocoa/tabpose_window.h" |
56 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 55 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
57 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 56 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
58 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 57 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
59 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 58 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
60 #include "chrome/browser/ui/omnibox/location_bar.h" | 59 #include "chrome/browser/ui/omnibox/location_bar.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 277 |
279 // Size and position the window. Note that it is not yet onscreen. Popup | 278 // Size and position the window. Note that it is not yet onscreen. Popup |
280 // windows may get resized later on in this function, once the actual size | 279 // windows may get resized later on in this function, once the actual size |
281 // of the toolbar/tabstrip is known. | 280 // of the toolbar/tabstrip is known. |
282 windowShim_->SetBounds(windowRect); | 281 windowShim_->SetBounds(windowRect); |
283 | 282 |
284 // Puts the incognito badge on the window frame, if necessary. | 283 // Puts the incognito badge on the window frame, if necessary. |
285 [self installAvatar]; | 284 [self installAvatar]; |
286 | 285 |
287 // Create a sub-controller for the docked devTools and add its view to the | 286 // Create a sub-controller for the docked devTools and add its view to the |
288 // hierarchy. This must happen before the sidebar controller is | 287 // hierarchy. |
289 // instantiated. | |
290 devToolsController_.reset( | 288 devToolsController_.reset( |
291 [[DevToolsController alloc] initWithDelegate:self]); | 289 [[DevToolsController alloc] initWithDelegate:self]); |
292 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; | 290 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; |
293 [[self tabContentArea] addSubview:[devToolsController_ view]]; | 291 [[self tabContentArea] addSubview:[devToolsController_ view]]; |
294 | 292 |
295 // Create a sub-controller for the docked sidebar and add its view to the | |
296 // hierarchy. This must happen before the previewable contents controller | |
297 // is instantiated. | |
298 sidebarController_.reset([[SidebarController alloc] initWithDelegate:self]); | |
299 [[sidebarController_ view] setFrame:[[devToolsController_ view] bounds]]; | |
300 [[devToolsController_ view] addSubview:[sidebarController_ view]]; | |
301 | |
302 // Create the previewable contents controller. This provides the switch | 293 // Create the previewable contents controller. This provides the switch |
303 // view that TabStripController needs. | 294 // view that TabStripController needs. |
304 previewableContentsController_.reset( | 295 previewableContentsController_.reset( |
305 [[PreviewableContentsController alloc] init]); | 296 [[PreviewableContentsController alloc] init]); |
306 [[previewableContentsController_ view] | 297 [[previewableContentsController_ view] |
307 setFrame:[[sidebarController_ view] bounds]]; | 298 setFrame:[[devToolsController_ view] bounds]]; |
308 [[sidebarController_ view] | 299 [[devToolsController_ view] |
309 addSubview:[previewableContentsController_ view]]; | 300 addSubview:[previewableContentsController_ view]]; |
310 | 301 |
311 // Create a controller for the tab strip, giving it the model object for | 302 // Create a controller for the tab strip, giving it the model object for |
312 // this window's Browser and the tab strip view. The controller will handle | 303 // this window's Browser and the tab strip view. The controller will handle |
313 // registering for the appropriate tab notifications from the back-end and | 304 // registering for the appropriate tab notifications from the back-end and |
314 // managing the creation of new tabs. | 305 // managing the creation of new tabs. |
315 [self createTabStripController]; | 306 [self createTabStripController]; |
316 | 307 |
317 // Create a controller for the toolbar, giving it the toolbar model object | 308 // Create a controller for the toolbar, giving it the toolbar model object |
318 // and the toolbar view from the nib. The controller will handle | 309 // and the toolbar view from the nib. The controller will handle |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 [devToolsController_ updateDevToolsForWebContents:contents | 520 [devToolsController_ updateDevToolsForWebContents:contents |
530 withProfile:browser_->profile()]; | 521 withProfile:browser_->profile()]; |
531 [devToolsController_ ensureContentsVisible]; | 522 [devToolsController_ ensureContentsVisible]; |
532 } | 523 } |
533 | 524 |
534 - (void)setDevToolsDockToRight:(bool)dock_to_right { | 525 - (void)setDevToolsDockToRight:(bool)dock_to_right { |
535 [devToolsController_ setDockToRight:dock_to_right | 526 [devToolsController_ setDockToRight:dock_to_right |
536 withProfile:browser_->profile()]; | 527 withProfile:browser_->profile()]; |
537 } | 528 } |
538 | 529 |
539 - (void)updateSidebarForContents:(TabContents*)contents { | |
540 [sidebarController_ updateSidebarForTabContents:contents]; | |
541 [sidebarController_ ensureContentsVisible]; | |
542 } | |
543 | |
544 // Called when the user wants to close a window or from the shutdown process. | 530 // Called when the user wants to close a window or from the shutdown process. |
545 // The Browser object is in control of whether or not we're allowed to close. It | 531 // The Browser object is in control of whether or not we're allowed to close. It |
546 // may defer closing due to several states, such as onUnload handlers needing to | 532 // may defer closing due to several states, such as onUnload handlers needing to |
547 // be fired. If closing is deferred, the Browser will handle the processing | 533 // be fired. If closing is deferred, the Browser will handle the processing |
548 // required to get us to the closing state and (by watching for all the tabs | 534 // required to get us to the closing state and (by watching for all the tabs |
549 // going away) will again call to close the window when it's finally ready. | 535 // going away) will again call to close the window when it's finally ready. |
550 - (BOOL)windowShouldClose:(id)sender { | 536 - (BOOL)windowShouldClose:(id)sender { |
551 // Disable updates while closing all tabs to avoid flickering. | 537 // Disable updates while closing all tabs to avoid flickering. |
552 gfx::ScopedNSDisableScreenUpdates disabler; | 538 gfx::ScopedNSDisableScreenUpdates disabler; |
553 // Give beforeunload handlers the chance to cancel the close before we hide | 539 // Give beforeunload handlers the chance to cancel the close before we hide |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 } | 1504 } |
1519 | 1505 |
1520 // TabStripControllerDelegate protocol. | 1506 // TabStripControllerDelegate protocol. |
1521 - (void)onActivateTabWithContents:(WebContents*)contents { | 1507 - (void)onActivateTabWithContents:(WebContents*)contents { |
1522 // Update various elements that are interested in knowing the current | 1508 // Update various elements that are interested in knowing the current |
1523 // TabContents. | 1509 // TabContents. |
1524 | 1510 |
1525 // Update all the UI bits. | 1511 // Update all the UI bits. |
1526 windowShim_->UpdateTitleBar(); | 1512 windowShim_->UpdateTitleBar(); |
1527 | 1513 |
1528 [sidebarController_ updateSidebarForTabContents: | |
1529 static_cast<TabContents*>(contents)]; | |
1530 [devToolsController_ updateDevToolsForWebContents:contents | 1514 [devToolsController_ updateDevToolsForWebContents:contents |
1531 withProfile:browser_->profile()]; | 1515 withProfile:browser_->profile()]; |
1532 | 1516 |
1533 // Update the bookmark bar. | 1517 // Update the bookmark bar. |
1534 // Must do it after sidebar and devtools update, otherwise bookmark bar might | 1518 // Must do it after devtools updates, otherwise bookmark bar might |
1535 // call resizeView -> layoutSubviews and cause unnecessary relayout. | 1519 // call resizeView -> layoutSubviews and cause unnecessary relayout. |
1536 // TODO(viettrungluu): perhaps update to not terminate running animations (if | 1520 // TODO(viettrungluu): perhaps update to not terminate running animations (if |
1537 // applicable)? | 1521 // applicable)? |
1538 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1522 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
1539 | 1523 |
1540 TabContentsWrapper* wrapper = | 1524 TabContentsWrapper* wrapper = |
1541 TabContentsWrapper::GetCurrentWrapperForContents(contents); | 1525 TabContentsWrapper::GetCurrentWrapperForContents(contents); |
1542 // Without the .get(), xcode fails. | 1526 // Without the .get(), xcode fails. |
1543 [infoBarContainerController_.get() changeTabContents:wrapper]; | 1527 [infoBarContainerController_.get() changeTabContents:wrapper]; |
1544 | 1528 |
1545 // Update devTools and sidebar contents after size for all views is set. | 1529 // Update devTools contents after size for all views is set. |
1546 [sidebarController_ ensureContentsVisible]; | |
1547 [devToolsController_ ensureContentsVisible]; | 1530 [devToolsController_ ensureContentsVisible]; |
1548 } | 1531 } |
1549 | 1532 |
1550 - (void)onReplaceTabWithContents:(WebContents*)contents { | 1533 - (void)onReplaceTabWithContents:(WebContents*)contents { |
1551 // Simply remove the preview view if it exists; the tab strip | 1534 // Simply remove the preview view if it exists; the tab strip |
1552 // controller will reinstall the view as the active view. | 1535 // controller will reinstall the view as the active view. |
1553 [previewableContentsController_ hidePreview]; | 1536 [previewableContentsController_ hidePreview]; |
1554 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1537 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
1555 } | 1538 } |
1556 | 1539 |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2189 | 2172 |
2190 - (BOOL)supportsBookmarkBar { | 2173 - (BOOL)supportsBookmarkBar { |
2191 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2174 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2192 } | 2175 } |
2193 | 2176 |
2194 - (BOOL)isTabbedWindow { | 2177 - (BOOL)isTabbedWindow { |
2195 return browser_->is_type_tabbed(); | 2178 return browser_->is_type_tabbed(); |
2196 } | 2179 } |
2197 | 2180 |
2198 @end // @implementation BrowserWindowController(WindowType) | 2181 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |