| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/tabs/tab_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 8 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| 9 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 9 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 10 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 10 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 themeImagePositionForAlignment:alignment]; | 40 themeImagePositionForAlignment:alignment]; |
| 41 } | 41 } |
| 42 return NSZeroPoint; | 42 return NSZeroPoint; |
| 43 } | 43 } |
| 44 | 44 |
| 45 @end | 45 @end |
| 46 | 46 |
| 47 @implementation TabWindowController | 47 @implementation TabWindowController |
| 48 | 48 |
| 49 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip { | 49 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip { |
| 50 const CGFloat kDefaultWidth = 750; | 50 NSRect contentRect = NSMakeRect(60, 229, 750, 600); |
| 51 const CGFloat kDefaultHeight = 600; | |
| 52 | |
| 53 NSRect contentRect = NSMakeRect(60, 229, kDefaultWidth, kDefaultHeight); | |
| 54 base::scoped_nsobject<FramedBrowserWindow> window( | 51 base::scoped_nsobject<FramedBrowserWindow> window( |
| 55 [[FramedBrowserWindow alloc] initWithContentRect:contentRect | 52 [[FramedBrowserWindow alloc] initWithContentRect:contentRect |
| 56 hasTabStrip:hasTabStrip]); | 53 hasTabStrip:hasTabStrip]); |
| 57 [window setReleasedWhenClosed:YES]; | 54 [window setReleasedWhenClosed:YES]; |
| 58 [window setAutorecalculatesKeyViewLoop:YES]; | 55 [window setAutorecalculatesKeyViewLoop:YES]; |
| 59 | 56 |
| 60 if ((self = [super initWithWindow:window])) { | 57 if ((self = [super initWithWindow:window])) { |
| 61 [[self window] setDelegate:self]; | 58 [[self window] setDelegate:self]; |
| 62 | 59 |
| 63 chromeContentView_.reset([[NSView alloc] | 60 tabContentArea_.reset([[FastResizeView alloc] initWithFrame: |
| 64 initWithFrame:NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight)]); | 61 NSMakeRect(0, 0, 750, 600)]); |
| 65 [chromeContentView_ | |
| 66 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | |
| 67 [[[self window] contentView] addSubview:chromeContentView_]; | |
| 68 | |
| 69 tabContentArea_.reset( | |
| 70 [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]); | |
| 71 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | | 62 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | |
| 72 NSViewHeightSizable]; | 63 NSViewHeightSizable]; |
| 73 [chromeContentView_ addSubview:tabContentArea_]; | 64 [[[self window] contentView] addSubview:tabContentArea_]; |
| 74 | 65 |
| 75 tabStripView_.reset([[TabStripView alloc] | 66 tabStripView_.reset([[TabStripView alloc] initWithFrame: |
| 76 initWithFrame:NSMakeRect(0, 0, kDefaultWidth, 37)]); | 67 NSMakeRect(0, 0, 750, 37)]); |
| 77 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | | 68 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | |
| 78 NSViewMinYMargin]; | 69 NSViewMinYMargin]; |
| 79 if (hasTabStrip) | 70 if (hasTabStrip) |
| 80 [self addTabStripToWindow]; | 71 [self addTabStripToWindow]; |
| 81 } | 72 } |
| 82 return self; | 73 return self; |
| 83 } | 74 } |
| 84 | 75 |
| 85 - (TabStripView*)tabStripView { | 76 - (TabStripView*)tabStripView { |
| 86 return tabStripView_; | 77 return tabStripView_; |
| 87 } | 78 } |
| 88 | 79 |
| 89 - (FastResizeView*)tabContentArea { | 80 - (FastResizeView*)tabContentArea { |
| 90 return tabContentArea_; | 81 return tabContentArea_; |
| 91 } | 82 } |
| 92 | 83 |
| 93 - (NSView*)chromeContentView { | |
| 94 return chromeContentView_; | |
| 95 } | |
| 96 | |
| 97 // Add the top tab strop to the window, above the content box and add it to the | 84 // Add the top tab strop to the window, above the content box and add it to the |
| 98 // view hierarchy as a sibling of the content view so it can overlap with the | 85 // view hierarchy as a sibling of the content view so it can overlap with the |
| 99 // window frame. | 86 // window frame. |
| 100 - (void)addTabStripToWindow { | 87 - (void)addTabStripToWindow { |
| 101 // The frame doesn't matter. This class relies on subclasses to do tab strip | 88 // The frame doesn't matter. This class relies on subclasses to do tab strip |
| 102 // layout. | 89 // layout. |
| 103 NSView* contentParent = [[self window] cr_windowView]; | 90 NSView* contentParent = [[self window] cr_windowView]; |
| 104 [contentParent addSubview:tabStripView_]; | 91 [contentParent addSubview:tabStripView_]; |
| 105 } | 92 } |
| 106 | 93 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 133 overlayWindow_ = [[TabWindowOverlayWindow alloc] | 120 overlayWindow_ = [[TabWindowOverlayWindow alloc] |
| 134 initWithContentRect:[window frame] | 121 initWithContentRect:[window frame] |
| 135 styleMask:NSBorderlessWindowMask | 122 styleMask:NSBorderlessWindowMask |
| 136 backing:NSBackingStoreBuffered | 123 backing:NSBackingStoreBuffered |
| 137 defer:YES]; | 124 defer:YES]; |
| 138 [overlayWindow_ setTitle:@"overlay"]; | 125 [overlayWindow_ setTitle:@"overlay"]; |
| 139 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; | 126 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; |
| 140 [overlayWindow_ setOpaque:NO]; | 127 [overlayWindow_ setOpaque:NO]; |
| 141 [overlayWindow_ setDelegate:self]; | 128 [overlayWindow_ setDelegate:self]; |
| 142 | 129 |
| 143 originalContentView_ = self.chromeContentView; | 130 originalContentView_ = [window contentView]; |
| 144 [window addChildWindow:overlayWindow_ ordered:NSWindowAbove]; | 131 [window addChildWindow:overlayWindow_ ordered:NSWindowAbove]; |
| 145 | 132 |
| 146 // Explicitly set the responder to be nil here (for restoring later). | 133 // Explicitly set the responder to be nil here (for restoring later). |
| 147 // If the first responder were to be left non-nil here then | 134 // If the first responder were to be left non-nil here then |
| 148 // [RenderWidgethostViewCocoa resignFirstResponder] would be called, | 135 // [RenderWidgethostViewCocoa resignFirstResponder] would be called, |
| 149 // followed by RenderWidgetHost::Blur(), which would result in an unexpected | 136 // followed by RenderWidgetHost::Blur(), which would result in an unexpected |
| 150 // loss of focus. | 137 // loss of focus. |
| 151 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]); | 138 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]); |
| 152 [window makeFirstResponder:nil]; | 139 [window makeFirstResponder:nil]; |
| 153 | 140 |
| 154 // Move the original window's tab strip view and content view to the overlay | 141 // Move the original window's tab strip view and content view to the overlay |
| 155 // window. The content view is added as a subview of the overlay window's | 142 // window. The content view is added as a subview of the overlay window's |
| 156 // content view (rather than using setContentView:) because the overlay | 143 // content view (rather than using setContentView:) because the overlay |
| 157 // window has a different content size (due to it being borderless). | 144 // window has a different content size (due to it being borderless). |
| 158 [[overlayWindow_ cr_windowView] addSubview:[self tabStripView]]; | 145 [[overlayWindow_ cr_windowView] addSubview:[self tabStripView]]; |
| 159 [[overlayWindow_ contentView] addSubview:originalContentView_]; | 146 [[overlayWindow_ contentView] addSubview:originalContentView_]; |
| 160 | 147 |
| 161 [overlayWindow_ orderFront:nil]; | 148 [overlayWindow_ orderFront:nil]; |
| 162 } else if (!useOverlay && overlayWindow_) { | 149 } else if (!useOverlay && overlayWindow_) { |
| 163 DCHECK(originalContentView_); | 150 DCHECK(originalContentView_); |
| 164 | 151 |
| 165 // Return the original window's tab strip view and content view to their | 152 // Return the original window's tab strip view and content view to their |
| 166 // places. The TabStripView always needs to be in front of the window's | 153 // places. The TabStripView always needs to be in front of the window's |
| 167 // content view and therefore it should always be added after the content | 154 // content view and therefore it should always be added after the content |
| 168 // view is set. | 155 // view is set. |
| 169 [[window contentView] addSubview:originalContentView_ | 156 [window setContentView:originalContentView_]; |
| 170 positioned:NSWindowBelow | |
| 171 relativeTo:nil]; | |
| 172 originalContentView_.frame = [[window contentView] bounds]; | |
| 173 [[window cr_windowView] addSubview:[self tabStripView]]; | 157 [[window cr_windowView] addSubview:[self tabStripView]]; |
| 174 [[window cr_windowView] updateTrackingAreas]; | 158 [[window cr_windowView] updateTrackingAreas]; |
| 175 | 159 |
| 176 [focusBeforeOverlay_ restoreFocusInWindow:window]; | 160 [focusBeforeOverlay_ restoreFocusInWindow:window]; |
| 177 focusBeforeOverlay_.reset(); | 161 focusBeforeOverlay_.reset(); |
| 178 | 162 |
| 179 [window display]; | 163 [window display]; |
| 180 [window removeChildWindow:overlayWindow_]; | 164 [window removeChildWindow:overlayWindow_]; |
| 181 | 165 |
| 182 [overlayWindow_ orderOut:nil]; | 166 [overlayWindow_ orderOut:nil]; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 closeDeferred_ = YES; | 292 closeDeferred_ = YES; |
| 309 } | 293 } |
| 310 | 294 |
| 311 // Called when the size of the window content area has changed. Override to | 295 // Called when the size of the window content area has changed. Override to |
| 312 // position specific views. Base class implementation does nothing. | 296 // position specific views. Base class implementation does nothing. |
| 313 - (void)layoutSubviews { | 297 - (void)layoutSubviews { |
| 314 NOTIMPLEMENTED(); | 298 NOTIMPLEMENTED(); |
| 315 } | 299 } |
| 316 | 300 |
| 317 @end | 301 @end |
| OLD | NEW |