| 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 <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "app/mac/scoped_nsdisable_screen_updates.h" | |
| 10 #include "app/mac/nsimage_cache.h" | |
| 11 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 12 #import "base/memory/scoped_nsobject.h" | 10 #import "base/memory/scoped_nsobject.h" |
| 13 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| 14 #include "chrome/app/chrome_command_ids.h" // IDC_* | 12 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 15 #include "chrome/browser/bookmarks/bookmark_editor.h" | 13 #include "chrome/browser/bookmarks/bookmark_editor.h" |
| 16 #include "chrome/browser/google/google_util.h" | 14 #include "chrome/browser/google/google_util.h" |
| 17 #include "chrome/browser/instant/instant_controller.h" | 15 #include "chrome/browser/instant/instant_controller.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/sync/profile_sync_service.h" | 17 #include "chrome/browser/sync/profile_sync_service.h" |
| 20 #include "chrome/browser/sync/sync_ui_util_mac.h" | 18 #include "chrome/browser/sync/sync_ui_util_mac.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 #import "chrome/browser/ui/cocoa/fullscreen_controller.h" | 37 #import "chrome/browser/ui/cocoa/fullscreen_controller.h" |
| 40 #import "chrome/browser/ui/cocoa/fullscreen_window.h" | 38 #import "chrome/browser/ui/cocoa/fullscreen_window.h" |
| 41 #import "chrome/browser/ui/cocoa/image_utils.h" | 39 #import "chrome/browser/ui/cocoa/image_utils.h" |
| 42 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 40 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 43 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| 44 #import "chrome/browser/ui/cocoa/sidebar_controller.h" | 42 #import "chrome/browser/ui/cocoa/sidebar_controller.h" |
| 45 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 43 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 46 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" | 44 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" |
| 47 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 45 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
| 48 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 46 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 47 #import "chrome/browser/ui/cocoa/tabpose_window.h" |
| 49 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 48 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 50 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 49 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 51 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 50 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 52 #import "chrome/browser/ui/cocoa/tabpose_window.h" | |
| 53 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 51 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 54 #include "chrome/browser/ui/omnibox/location_bar.h" | 52 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 55 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 53 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 56 #include "chrome/browser/ui/tabs/dock_info.h" | 54 #include "chrome/browser/ui/tabs/dock_info.h" |
| 57 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 55 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
| 58 #include "chrome/browser/ui/window_sizer.h" | 56 #include "chrome/browser/ui/window_sizer.h" |
| 59 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
| 60 #include "content/browser/renderer_host/render_widget_host_view.h" | 58 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 61 #include "content/browser/tab_contents/tab_contents.h" | 59 #include "content/browser/tab_contents/tab_contents.h" |
| 62 #include "grit/generated_resources.h" | 60 #include "grit/generated_resources.h" |
| 63 #include "grit/locale_settings.h" | 61 #include "grit/locale_settings.h" |
| 64 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
| 65 #include "ui/base/l10n/l10n_util_mac.h" | 63 #include "ui/base/l10n/l10n_util_mac.h" |
| 64 #include "ui/gfx/mac/nsimage_cache.h" |
| 65 #include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" |
| 66 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 66 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 67 | 67 |
| 68 | 68 |
| 69 // ORGANIZATION: This is a big file. It is (in principle) organized as follows | 69 // ORGANIZATION: This is a big file. It is (in principle) organized as follows |
| 70 // (in order): | 70 // (in order): |
| 71 // 1. Interfaces. Very short, one-time-use classes may include an implementation | 71 // 1. Interfaces. Very short, one-time-use classes may include an implementation |
| 72 // immediately after their interface. | 72 // immediately after their interface. |
| 73 // 2. The general implementation section, ordered as follows: | 73 // 2. The general implementation section, ordered as follows: |
| 74 // i. Public methods and overrides. | 74 // i. Public methods and overrides. |
| 75 // ii. Overrides/implementations of undocumented methods. | 75 // ii. Overrides/implementations of undocumented methods. |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 } | 535 } |
| 536 | 536 |
| 537 // Called when the user wants to close a window or from the shutdown process. | 537 // Called when the user wants to close a window or from the shutdown process. |
| 538 // The Browser object is in control of whether or not we're allowed to close. It | 538 // The Browser object is in control of whether or not we're allowed to close. It |
| 539 // may defer closing due to several states, such as onUnload handlers needing to | 539 // may defer closing due to several states, such as onUnload handlers needing to |
| 540 // be fired. If closing is deferred, the Browser will handle the processing | 540 // be fired. If closing is deferred, the Browser will handle the processing |
| 541 // required to get us to the closing state and (by watching for all the tabs | 541 // required to get us to the closing state and (by watching for all the tabs |
| 542 // going away) will again call to close the window when it's finally ready. | 542 // going away) will again call to close the window when it's finally ready. |
| 543 - (BOOL)windowShouldClose:(id)sender { | 543 - (BOOL)windowShouldClose:(id)sender { |
| 544 // Disable updates while closing all tabs to avoid flickering. | 544 // Disable updates while closing all tabs to avoid flickering. |
| 545 app::mac::ScopedNSDisableScreenUpdates disabler; | 545 gfx::ScopedNSDisableScreenUpdates disabler; |
| 546 // Give beforeunload handlers the chance to cancel the close before we hide | 546 // Give beforeunload handlers the chance to cancel the close before we hide |
| 547 // the window below. | 547 // the window below. |
| 548 if (!browser_->ShouldCloseWindow()) | 548 if (!browser_->ShouldCloseWindow()) |
| 549 return NO; | 549 return NO; |
| 550 | 550 |
| 551 // saveWindowPositionIfNeeded: only works if we are the last active | 551 // saveWindowPositionIfNeeded: only works if we are the last active |
| 552 // window, but orderOut: ends up activating another window, so we | 552 // window, but orderOut: ends up activating another window, so we |
| 553 // have to save the window position before we call orderOut:. | 553 // have to save the window position before we call orderOut:. |
| 554 [self saveWindowPositionIfNeeded]; | 554 [self saveWindowPositionIfNeeded]; |
| 555 | 555 |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 - (void)focusTabContents { | 1237 - (void)focusTabContents { |
| 1238 [[self window] makeFirstResponder:[tabStripController_ activeTabView]]; | 1238 [[self window] makeFirstResponder:[tabStripController_ activeTabView]]; |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 - (void)layoutTabs { | 1241 - (void)layoutTabs { |
| 1242 [tabStripController_ layoutTabs]; | 1242 [tabStripController_ layoutTabs]; |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView { | 1245 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView { |
| 1246 // Disable screen updates so that this appears as a single visual change. | 1246 // Disable screen updates so that this appears as a single visual change. |
| 1247 app::mac::ScopedNSDisableScreenUpdates disabler; | 1247 gfx::ScopedNSDisableScreenUpdates disabler; |
| 1248 | 1248 |
| 1249 // Fetch the tab contents for the tab being dragged. | 1249 // Fetch the tab contents for the tab being dragged. |
| 1250 int index = [tabStripController_ modelIndexForTabView:tabView]; | 1250 int index = [tabStripController_ modelIndexForTabView:tabView]; |
| 1251 TabContentsWrapper* contents = browser_->GetTabContentsWrapperAt(index); | 1251 TabContentsWrapper* contents = browser_->GetTabContentsWrapperAt(index); |
| 1252 | 1252 |
| 1253 // Set the window size. Need to do this before we detach the tab so it's | 1253 // Set the window size. Need to do this before we detach the tab so it's |
| 1254 // still in the window. We have to flip the coordinates as that's what | 1254 // still in the window. We have to flip the coordinates as that's what |
| 1255 // is expected by the Browser code. | 1255 // is expected by the Browser code. |
| 1256 NSWindow* sourceWindow = [tabView window]; | 1256 NSWindow* sourceWindow = [tabView window]; |
| 1257 NSRect windowRect = [sourceWindow frame]; | 1257 NSRect windowRect = [sourceWindow frame]; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 // If the browser is in incognito mode, install the image view to decorate | 1637 // If the browser is in incognito mode, install the image view to decorate |
| 1638 // the window at the upper right. Use the same base y coordinate as the | 1638 // the window at the upper right. Use the same base y coordinate as the |
| 1639 // tab strip. | 1639 // tab strip. |
| 1640 - (void)installIncognitoBadge { | 1640 - (void)installIncognitoBadge { |
| 1641 // Only install if this browser window is OTR and has a tab strip. | 1641 // Only install if this browser window is OTR and has a tab strip. |
| 1642 if (!browser_->profile()->IsOffTheRecord() || ![self hasTabStrip]) | 1642 if (!browser_->profile()->IsOffTheRecord() || ![self hasTabStrip]) |
| 1643 return; | 1643 return; |
| 1644 | 1644 |
| 1645 // Install the image into the badge view and size the view appropriately. | 1645 // Install the image into the badge view and size the view appropriately. |
| 1646 // Hide it for now; positioning and showing will be done by the layout code. | 1646 // Hide it for now; positioning and showing will be done by the layout code. |
| 1647 NSImage* image = app::mac::GetCachedImageWithName(@"otr_icon.pdf"); | 1647 NSImage* image = gfx::GetCachedImageWithName(@"otr_icon.pdf"); |
| 1648 incognitoBadge_.reset([[IncognitoImageView alloc] init]); | 1648 incognitoBadge_.reset([[IncognitoImageView alloc] init]); |
| 1649 [incognitoBadge_ setImage:image]; | 1649 [incognitoBadge_ setImage:image]; |
| 1650 [incognitoBadge_ setFrameSize:[image size]]; | 1650 [incognitoBadge_ setFrameSize:[image size]]; |
| 1651 [incognitoBadge_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 1651 [incognitoBadge_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 1652 [incognitoBadge_ setHidden:YES]; | 1652 [incognitoBadge_ setHidden:YES]; |
| 1653 | 1653 |
| 1654 // Install the view. | 1654 // Install the view. |
| 1655 [[[[self window] contentView] superview] addSubview:incognitoBadge_]; | 1655 [[[[self window] contentView] superview] addSubview:incognitoBadge_]; |
| 1656 } | 1656 } |
| 1657 | 1657 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 | 2201 |
| 2202 - (BOOL)supportsBookmarkBar { | 2202 - (BOOL)supportsBookmarkBar { |
| 2203 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2203 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2204 } | 2204 } |
| 2205 | 2205 |
| 2206 - (BOOL)isTabbedWindow { | 2206 - (BOOL)isTabbedWindow { |
| 2207 return browser_->is_type_tabbed(); | 2207 return browser_->is_type_tabbed(); |
| 2208 } | 2208 } |
| 2209 | 2209 |
| 2210 @end // @implementation BrowserWindowController(WindowType) | 2210 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |