| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/l10n_util_mac.h" | 10 #include "app/l10n_util_mac.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "chrome/browser/dock_info.h" | 47 #include "chrome/browser/dock_info.h" |
| 48 #include "chrome/browser/encoding_menu_controller.h" | 48 #include "chrome/browser/encoding_menu_controller.h" |
| 49 #include "chrome/browser/google/google_util.h" | 49 #include "chrome/browser/google/google_util.h" |
| 50 #include "chrome/browser/location_bar.h" | 50 #include "chrome/browser/location_bar.h" |
| 51 #include "chrome/browser/profile.h" | 51 #include "chrome/browser/profile.h" |
| 52 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 52 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 53 #include "chrome/browser/sync/profile_sync_service.h" | 53 #include "chrome/browser/sync/profile_sync_service.h" |
| 54 #include "chrome/browser/sync/sync_ui_util_mac.h" | 54 #include "chrome/browser/sync/sync_ui_util_mac.h" |
| 55 #include "chrome/browser/tab_contents/tab_contents.h" | 55 #include "chrome/browser/tab_contents/tab_contents.h" |
| 56 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" | 56 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
| 57 #include "chrome/browser/tab_contents_wrapper.h" |
| 57 #include "chrome/browser/tabs/tab_strip_model.h" | 58 #include "chrome/browser/tabs/tab_strip_model.h" |
| 58 #include "chrome/browser/themes/browser_theme_provider.h" | 59 #include "chrome/browser/themes/browser_theme_provider.h" |
| 59 #include "chrome/browser/window_sizer.h" | 60 #include "chrome/browser/window_sizer.h" |
| 60 #include "chrome/common/url_constants.h" | 61 #include "chrome/common/url_constants.h" |
| 61 #include "grit/generated_resources.h" | 62 #include "grit/generated_resources.h" |
| 62 #include "grit/locale_settings.h" | 63 #include "grit/locale_settings.h" |
| 63 | 64 |
| 64 // ORGANIZATION: This is a big file. It is (in principle) organized as follows | 65 // ORGANIZATION: This is a big file. It is (in principle) organized as follows |
| 65 // (in order): | 66 // (in order): |
| 66 // 1. Interfaces. Very short, one-time-use classes may include an implementation | 67 // 1. Interfaces. Very short, one-time-use classes may include an implementation |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 } | 610 } |
| 610 | 611 |
| 611 // To prevent strange results on portrait displays, the basic minimum zoomed | 612 // To prevent strange results on portrait displays, the basic minimum zoomed |
| 612 // width is the larger of: 60% of available width, 60% of available height | 613 // width is the larger of: 60% of available width, 60% of available height |
| 613 // (bounded by available width). | 614 // (bounded by available width). |
| 614 const CGFloat kProportion = 0.6; | 615 const CGFloat kProportion = 0.6; |
| 615 CGFloat zoomedWidth = | 616 CGFloat zoomedWidth = |
| 616 std::max(kProportion * frame.size.width, | 617 std::max(kProportion * frame.size.width, |
| 617 std::min(kProportion * frame.size.height, frame.size.width)); | 618 std::min(kProportion * frame.size.height, frame.size.width)); |
| 618 | 619 |
| 619 TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); | 620 TabContents* contents = browser_->GetSelectedTabContents(); |
| 620 if (contents) { | 621 if (contents) { |
| 621 // If the intrinsic width is bigger, then make it the zoomed width. | 622 // If the intrinsic width is bigger, then make it the zoomed width. |
| 622 const int kScrollbarWidth = 16; // TODO(viettrungluu): ugh. | 623 const int kScrollbarWidth = 16; // TODO(viettrungluu): ugh. |
| 623 TabContentsViewMac* tab_contents_view = | 624 TabContentsViewMac* tab_contents_view = |
| 624 static_cast<TabContentsViewMac*>(contents->view()); | 625 static_cast<TabContentsViewMac*>(contents->view()); |
| 625 CGFloat intrinsicWidth = static_cast<CGFloat>( | 626 CGFloat intrinsicWidth = static_cast<CGFloat>( |
| 626 tab_contents_view->preferred_width() + kScrollbarWidth); | 627 tab_contents_view->preferred_width() + kScrollbarWidth); |
| 627 zoomedWidth = std::max(zoomedWidth, | 628 zoomedWidth = std::max(zoomedWidth, |
| 628 std::min(intrinsicWidth, frame.size.width)); | 629 std::min(intrinsicWidth, frame.size.width)); |
| 629 } | 630 } |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 fromController:(TabWindowController*)dragController { | 1080 fromController:(TabWindowController*)dragController { |
| 1080 if (dragController) { | 1081 if (dragController) { |
| 1081 // Moving between windows. Figure out the TabContents to drop into our tab | 1082 // Moving between windows. Figure out the TabContents to drop into our tab |
| 1082 // model from the source window's model. | 1083 // model from the source window's model. |
| 1083 BOOL isBrowser = | 1084 BOOL isBrowser = |
| 1084 [dragController isKindOfClass:[BrowserWindowController class]]; | 1085 [dragController isKindOfClass:[BrowserWindowController class]]; |
| 1085 DCHECK(isBrowser); | 1086 DCHECK(isBrowser); |
| 1086 if (!isBrowser) return; | 1087 if (!isBrowser) return; |
| 1087 BrowserWindowController* dragBWC = (BrowserWindowController*)dragController; | 1088 BrowserWindowController* dragBWC = (BrowserWindowController*)dragController; |
| 1088 int index = [dragBWC->tabStripController_ modelIndexForTabView:view]; | 1089 int index = [dragBWC->tabStripController_ modelIndexForTabView:view]; |
| 1089 TabContents* contents = | 1090 TabContentsWrapper* contents = |
| 1090 dragBWC->browser_->tabstrip_model()->GetTabContentsAt(index); | 1091 dragBWC->browser_->GetTabContentsWrapperAt(index); |
| 1091 // The tab contents may have gone away if given a window.close() while it | 1092 // The tab contents may have gone away if given a window.close() while it |
| 1092 // is being dragged. If so, bail, we've got nothing to drop. | 1093 // is being dragged. If so, bail, we've got nothing to drop. |
| 1093 if (!contents) | 1094 if (!contents) |
| 1094 return; | 1095 return; |
| 1095 | 1096 |
| 1096 // Convert |view|'s frame (which starts in the source tab strip's coordinate | 1097 // Convert |view|'s frame (which starts in the source tab strip's coordinate |
| 1097 // system) to the coordinate system of the destination tab strip. This needs | 1098 // system) to the coordinate system of the destination tab strip. This needs |
| 1098 // to be done before being detached so the window transforms can be | 1099 // to be done before being detached so the window transforms can be |
| 1099 // performed. | 1100 // performed. |
| 1100 NSRect destinationFrame = [view frame]; | 1101 NSRect destinationFrame = [view frame]; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 - (void)layoutTabs { | 1159 - (void)layoutTabs { |
| 1159 [tabStripController_ layoutTabs]; | 1160 [tabStripController_ layoutTabs]; |
| 1160 } | 1161 } |
| 1161 | 1162 |
| 1162 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView { | 1163 - (TabWindowController*)detachTabToNewWindow:(TabView*)tabView { |
| 1163 // Disable screen updates so that this appears as a single visual change. | 1164 // Disable screen updates so that this appears as a single visual change. |
| 1164 app::mac::ScopedNSDisableScreenUpdates disabler; | 1165 app::mac::ScopedNSDisableScreenUpdates disabler; |
| 1165 | 1166 |
| 1166 // Fetch the tab contents for the tab being dragged. | 1167 // Fetch the tab contents for the tab being dragged. |
| 1167 int index = [tabStripController_ modelIndexForTabView:tabView]; | 1168 int index = [tabStripController_ modelIndexForTabView:tabView]; |
| 1168 TabContents* contents = browser_->tabstrip_model()->GetTabContentsAt(index); | 1169 TabContentsWrapper* contents = browser_->GetTabContentsWrapperAt(index); |
| 1169 | 1170 |
| 1170 // Set the window size. Need to do this before we detach the tab so it's | 1171 // Set the window size. Need to do this before we detach the tab so it's |
| 1171 // still in the window. We have to flip the coordinates as that's what | 1172 // still in the window. We have to flip the coordinates as that's what |
| 1172 // is expected by the Browser code. | 1173 // is expected by the Browser code. |
| 1173 NSWindow* sourceWindow = [tabView window]; | 1174 NSWindow* sourceWindow = [tabView window]; |
| 1174 NSRect windowRect = [sourceWindow frame]; | 1175 NSRect windowRect = [sourceWindow frame]; |
| 1175 NSScreen* screen = [sourceWindow screen]; | 1176 NSScreen* screen = [sourceWindow screen]; |
| 1176 windowRect.origin.y = | 1177 windowRect.origin.y = |
| 1177 [screen frame].size.height - windowRect.size.height - | 1178 [screen frame].size.height - windowRect.size.height - |
| 1178 windowRect.origin.y; | 1179 windowRect.origin.y; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 - (NSInteger)numberOfTabs { | 1317 - (NSInteger)numberOfTabs { |
| 1317 // count() includes pinned tabs. | 1318 // count() includes pinned tabs. |
| 1318 return browser_->tabstrip_model()->count(); | 1319 return browser_->tabstrip_model()->count(); |
| 1319 } | 1320 } |
| 1320 | 1321 |
| 1321 - (BOOL)hasLiveTabs { | 1322 - (BOOL)hasLiveTabs { |
| 1322 return !browser_->tabstrip_model()->empty(); | 1323 return !browser_->tabstrip_model()->empty(); |
| 1323 } | 1324 } |
| 1324 | 1325 |
| 1325 - (NSString*)selectedTabTitle { | 1326 - (NSString*)selectedTabTitle { |
| 1326 TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); | 1327 TabContents* contents = browser_->GetSelectedTabContents(); |
| 1327 return base::SysUTF16ToNSString(contents->GetTitle()); | 1328 return base::SysUTF16ToNSString(contents->GetTitle()); |
| 1328 } | 1329 } |
| 1329 | 1330 |
| 1330 - (NSRect)regularWindowFrame { | 1331 - (NSRect)regularWindowFrame { |
| 1331 return [self isFullscreen] ? [savedRegularWindow_ frame] : | 1332 return [self isFullscreen] ? [savedRegularWindow_ frame] : |
| 1332 [[self window] frame]; | 1333 [[self window] frame]; |
| 1333 } | 1334 } |
| 1334 | 1335 |
| 1335 // (Override of |TabWindowController| method.) | 1336 // (Override of |TabWindowController| method.) |
| 1336 - (BOOL)hasTabStrip { | 1337 - (BOOL)hasTabStrip { |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 | 2043 |
| 2043 - (BOOL)supportsBookmarkBar { | 2044 - (BOOL)supportsBookmarkBar { |
| 2044 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2045 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2045 } | 2046 } |
| 2046 | 2047 |
| 2047 - (BOOL)isNormalWindow { | 2048 - (BOOL)isNormalWindow { |
| 2048 return browser_->type() == Browser::TYPE_NORMAL; | 2049 return browser_->type() == Browser::TYPE_NORMAL; |
| 2049 } | 2050 } |
| 2050 | 2051 |
| 2051 @end // @implementation BrowserWindowController(WindowType) | 2052 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |