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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 273 |
275 // Size and position the window. Note that it is not yet onscreen. Popup | 274 // Size and position the window. Note that it is not yet onscreen. Popup |
276 // windows may get resized later on in this function, once the actual size | 275 // windows may get resized later on in this function, once the actual size |
277 // of the toolbar/tabstrip is known. | 276 // of the toolbar/tabstrip is known. |
278 windowShim_->SetBounds(windowRect); | 277 windowShim_->SetBounds(windowRect); |
279 | 278 |
280 // Puts the incognito badge on the window frame, if necessary. | 279 // Puts the incognito badge on the window frame, if necessary. |
281 [self installAvatar]; | 280 [self installAvatar]; |
282 | 281 |
283 // Create a sub-controller for the docked devTools and add its view to the | 282 // Create a sub-controller for the docked devTools and add its view to the |
284 // hierarchy. This must happen before the sidebar controller is | 283 // hierarchy. |
285 // instantiated. | |
286 devToolsController_.reset( | 284 devToolsController_.reset( |
287 [[DevToolsController alloc] initWithDelegate:self]); | 285 [[DevToolsController alloc] initWithDelegate:self]); |
288 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; | 286 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; |
289 [[self tabContentArea] addSubview:[devToolsController_ view]]; | 287 [[self tabContentArea] addSubview:[devToolsController_ view]]; |
290 | 288 |
291 // Create a sub-controller for the docked sidebar and add its view to the | |
292 // hierarchy. This must happen before the previewable contents controller | |
293 // is instantiated. | |
294 sidebarController_.reset([[SidebarController alloc] initWithDelegate:self]); | |
295 [[sidebarController_ view] setFrame:[[devToolsController_ view] bounds]]; | |
296 [[devToolsController_ view] addSubview:[sidebarController_ view]]; | |
297 | |
298 // Create the previewable contents controller. This provides the switch | 289 // Create the previewable contents controller. This provides the switch |
299 // view that TabStripController needs. | 290 // view that TabStripController needs. |
300 previewableContentsController_.reset( | 291 previewableContentsController_.reset( |
301 [[PreviewableContentsController alloc] init]); | 292 [[PreviewableContentsController alloc] init]); |
302 [[previewableContentsController_ view] | |
303 setFrame:[[sidebarController_ view] bounds]]; | |
304 [[sidebarController_ view] | |
305 addSubview:[previewableContentsController_ view]]; | |
306 | 293 |
307 // Create a controller for the tab strip, giving it the model object for | 294 // Create a controller for the tab strip, giving it the model object for |
308 // this window's Browser and the tab strip view. The controller will handle | 295 // this window's Browser and the tab strip view. The controller will handle |
309 // registering for the appropriate tab notifications from the back-end and | 296 // registering for the appropriate tab notifications from the back-end and |
310 // managing the creation of new tabs. | 297 // managing the creation of new tabs. |
311 [self createTabStripController]; | 298 [self createTabStripController]; |
312 | 299 |
313 // Create a controller for the toolbar, giving it the toolbar model object | 300 // Create a controller for the toolbar, giving it the toolbar model object |
314 // and the toolbar view from the nib. The controller will handle | 301 // and the toolbar view from the nib. The controller will handle |
315 // registering for the appropriate command state changes from the back-end. | 302 // registering for the appropriate command state changes from the back-end. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 - (BOOL)canAttachConstrainedWindow { | 507 - (BOOL)canAttachConstrainedWindow { |
521 return ![previewableContentsController_ isShowingPreview]; | 508 return ![previewableContentsController_ isShowingPreview]; |
522 } | 509 } |
523 | 510 |
524 - (void)updateDevToolsForContents:(TabContents*)contents { | 511 - (void)updateDevToolsForContents:(TabContents*)contents { |
525 [devToolsController_ updateDevToolsForTabContents:contents | 512 [devToolsController_ updateDevToolsForTabContents:contents |
526 withProfile:browser_->profile()]; | 513 withProfile:browser_->profile()]; |
527 [devToolsController_ ensureContentsVisible]; | 514 [devToolsController_ ensureContentsVisible]; |
528 } | 515 } |
529 | 516 |
530 - (void)updateSidebarForContents:(TabContents*)contents { | |
531 [sidebarController_ updateSidebarForTabContents:contents]; | |
532 [sidebarController_ ensureContentsVisible]; | |
533 } | |
534 | |
535 // Called when the user wants to close a window or from the shutdown process. | 517 // Called when the user wants to close a window or from the shutdown process. |
536 // The Browser object is in control of whether or not we're allowed to close. It | 518 // The Browser object is in control of whether or not we're allowed to close. It |
537 // may defer closing due to several states, such as onUnload handlers needing to | 519 // may defer closing due to several states, such as onUnload handlers needing to |
538 // be fired. If closing is deferred, the Browser will handle the processing | 520 // be fired. If closing is deferred, the Browser will handle the processing |
539 // required to get us to the closing state and (by watching for all the tabs | 521 // required to get us to the closing state and (by watching for all the tabs |
540 // going away) will again call to close the window when it's finally ready. | 522 // going away) will again call to close the window when it's finally ready. |
541 - (BOOL)windowShouldClose:(id)sender { | 523 - (BOOL)windowShouldClose:(id)sender { |
542 // Disable updates while closing all tabs to avoid flickering. | 524 // Disable updates while closing all tabs to avoid flickering. |
543 gfx::ScopedNSDisableScreenUpdates disabler; | 525 gfx::ScopedNSDisableScreenUpdates disabler; |
544 // Give beforeunload handlers the chance to cancel the close before we hide | 526 // 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... |
1509 } | 1491 } |
1510 | 1492 |
1511 // TabStripControllerDelegate protocol. | 1493 // TabStripControllerDelegate protocol. |
1512 - (void)onActivateTabWithContents:(TabContents*)contents { | 1494 - (void)onActivateTabWithContents:(TabContents*)contents { |
1513 // Update various elements that are interested in knowing the current | 1495 // Update various elements that are interested in knowing the current |
1514 // TabContents. | 1496 // TabContents. |
1515 | 1497 |
1516 // Update all the UI bits. | 1498 // Update all the UI bits. |
1517 windowShim_->UpdateTitleBar(); | 1499 windowShim_->UpdateTitleBar(); |
1518 | 1500 |
1519 [sidebarController_ updateSidebarForTabContents:contents]; | |
1520 [devToolsController_ updateDevToolsForTabContents:contents | 1501 [devToolsController_ updateDevToolsForTabContents:contents |
1521 withProfile:browser_->profile()]; | 1502 withProfile:browser_->profile()]; |
1522 | 1503 |
1523 // Update the bookmark bar. | 1504 // Update the bookmark bar. |
1524 // Must do it after sidebar and devtools update, otherwise bookmark bar might | 1505 // Must do it after devtools update, otherwise bookmark bar might call |
1525 // call resizeView -> layoutSubviews and cause unnecessary relayout. | 1506 // resizeView -> layoutSubviews and cause unnecessary relayout. |
1526 // TODO(viettrungluu): perhaps update to not terminate running animations (if | 1507 // TODO(viettrungluu): perhaps update to not terminate running animations (if |
1527 // applicable)? | 1508 // applicable)? |
1528 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1509 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
1529 | 1510 |
1530 TabContentsWrapper* wrapper = | 1511 TabContentsWrapper* wrapper = |
1531 TabContentsWrapper::GetCurrentWrapperForContents(contents); | 1512 TabContentsWrapper::GetCurrentWrapperForContents(contents); |
1532 // Without the .get(), xcode fails. | 1513 // Without the .get(), xcode fails. |
1533 [infoBarContainerController_.get() changeTabContents:wrapper]; | 1514 [infoBarContainerController_.get() changeTabContents:wrapper]; |
1534 | 1515 |
1535 // Update devTools and sidebar contents after size for all views is set. | 1516 // Update devTools contents after size for all views is set. |
1536 [sidebarController_ ensureContentsVisible]; | |
1537 [devToolsController_ ensureContentsVisible]; | 1517 [devToolsController_ ensureContentsVisible]; |
1538 } | 1518 } |
1539 | 1519 |
1540 - (void)onReplaceTabWithContents:(TabContents*)contents { | 1520 - (void)onReplaceTabWithContents:(TabContents*)contents { |
1541 // Simply remove the preview view if it exists; the tab strip | 1521 // Simply remove the preview view if it exists; the tab strip |
1542 // controller will reinstall the view as the active view. | 1522 // controller will reinstall the view as the active view. |
1543 [previewableContentsController_ hidePreview]; | 1523 [previewableContentsController_ hidePreview]; |
1544 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1524 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
1545 } | 1525 } |
1546 | 1526 |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2177 | 2157 |
2178 - (BOOL)supportsBookmarkBar { | 2158 - (BOOL)supportsBookmarkBar { |
2179 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2159 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2180 } | 2160 } |
2181 | 2161 |
2182 - (BOOL)isTabbedWindow { | 2162 - (BOOL)isTabbedWindow { |
2183 return browser_->is_type_tabbed(); | 2163 return browser_->is_type_tabbed(); |
2184 } | 2164 } |
2185 | 2165 |
2186 @end // @implementation BrowserWindowController(WindowType) | 2166 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |