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/browser_window_layout.h" | 8 #import "chrome/browser/ui/cocoa/browser_window_layout.h" |
9 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 9 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
10 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 10 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 11 #import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h" |
11 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
12 #import "chrome/browser/ui/cocoa/themed_window.h" | 13 #import "chrome/browser/ui/cocoa/themed_window.h" |
13 #import "chrome/browser/ui/cocoa/version_independent_window.h" | 14 #import "chrome/browser/ui/cocoa/version_independent_window.h" |
14 #import "ui/base/cocoa/focus_tracker.h" | 15 #import "ui/base/cocoa/focus_tracker.h" |
15 #include "ui/base/theme_provider.h" | 16 #include "ui/base/theme_provider.h" |
16 | 17 |
17 @interface TabWindowController(PRIVATE) | 18 @interface TabWindowController(PRIVATE) |
18 - (void)setUseOverlay:(BOOL)useOverlay; | 19 - (void)setUseOverlay:(BOOL)useOverlay; |
19 @end | 20 @end |
20 | 21 |
(...skipping 24 matching lines...) Expand all Loading... |
45 | 46 |
46 @end | 47 @end |
47 | 48 |
48 @implementation TabWindowController | 49 @implementation TabWindowController |
49 | 50 |
50 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip { | 51 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip { |
51 NSRect contentRect = NSMakeRect(60, 229, 750, 600); | 52 NSRect contentRect = NSMakeRect(60, 229, 750, 600); |
52 base::scoped_nsobject<FramedBrowserWindow> window( | 53 base::scoped_nsobject<FramedBrowserWindow> window( |
53 [[FramedBrowserWindow alloc] initWithContentRect:contentRect | 54 [[FramedBrowserWindow alloc] initWithContentRect:contentRect |
54 hasTabStrip:hasTabStrip]); | 55 hasTabStrip:hasTabStrip]); |
55 [self moveContentViewToBack:[window contentView]]; | |
56 [window setReleasedWhenClosed:YES]; | 56 [window setReleasedWhenClosed:YES]; |
57 [window setAutorecalculatesKeyViewLoop:YES]; | 57 [window setAutorecalculatesKeyViewLoop:YES]; |
58 | 58 |
59 if ((self = [super initWithWindow:window])) { | 59 if ((self = [super initWithWindow:window])) { |
60 [[self window] setDelegate:self]; | 60 [[self window] setDelegate:self]; |
61 | 61 |
62 tabContentArea_.reset([[FastResizeView alloc] initWithFrame: | 62 tabContentArea_.reset([[FastResizeView alloc] initWithFrame: |
63 NSMakeRect(0, 0, 750, 600)]); | 63 NSMakeRect(0, 0, 750, 600)]); |
64 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | | 64 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | |
65 NSViewHeightSizable]; | 65 NSViewHeightSizable]; |
66 [[[self window] contentView] addSubview:tabContentArea_]; | 66 [[[self window] contentView] addSubview:tabContentArea_]; |
67 | 67 |
| 68 // tabStripBackgroundView_ draws the theme image behind the tab strip area. |
| 69 // When making a tab dragging window (setUseOverlay:), this view stays in |
| 70 // the parent window so that it can be translucent, while the tab strip view |
| 71 // moves to the child window and stays opaque. |
| 72 NSView* windowView = [window cr_windowView]; |
| 73 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] |
| 74 initWithFrame:NSMakeRect(0, |
| 75 NSMaxY([windowView bounds]) - |
| 76 kBrowserFrameViewPaintHeight, |
| 77 NSWidth([windowView bounds]), |
| 78 kBrowserFrameViewPaintHeight)]); |
| 79 [tabStripBackgroundView_ |
| 80 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
| 81 [windowView addSubview:tabStripBackgroundView_ |
| 82 positioned:NSWindowBelow |
| 83 relativeTo:nil]; |
| 84 |
| 85 [self moveContentViewToBack:[window contentView]]; |
| 86 |
68 tabStripView_.reset([[TabStripView alloc] | 87 tabStripView_.reset([[TabStripView alloc] |
69 initWithFrame:NSMakeRect(0, 0, 750, chrome::kTabStripHeight)]); | 88 initWithFrame:NSMakeRect(0, 0, 750, chrome::kTabStripHeight)]); |
70 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | | 89 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | |
71 NSViewMinYMargin]; | 90 NSViewMinYMargin]; |
72 if (hasTabStrip) | 91 if (hasTabStrip) |
73 [self insertTabStripView:tabStripView_ intoWindow:[self window]]; | 92 [self insertTabStripView:tabStripView_ intoWindow:[self window]]; |
74 } | 93 } |
75 return self; | 94 return self; |
76 } | 95 } |
77 | 96 |
| 97 - (NSView*)tabStripBackgroundView { |
| 98 return tabStripBackgroundView_; |
| 99 } |
| 100 |
78 - (TabStripView*)tabStripView { | 101 - (TabStripView*)tabStripView { |
79 return tabStripView_; | 102 return tabStripView_; |
80 } | 103 } |
81 | 104 |
82 - (FastResizeView*)tabContentArea { | 105 - (FastResizeView*)tabContentArea { |
83 return tabContentArea_; | 106 return tabContentArea_; |
84 } | 107 } |
85 | 108 |
86 - (void)removeOverlay { | 109 - (void)removeOverlay { |
87 [self setUseOverlay:NO]; | 110 [self setUseOverlay:NO]; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // drag is complete. This prevents a window (and its overlay) from going away | 305 // drag is complete. This prevents a window (and its overlay) from going away |
283 // during a drag. | 306 // during a drag. |
284 - (void)deferPerformClose { | 307 - (void)deferPerformClose { |
285 closeDeferred_ = YES; | 308 closeDeferred_ = YES; |
286 } | 309 } |
287 | 310 |
288 - (void)moveContentViewToBack:(NSView*)cv { | 311 - (void)moveContentViewToBack:(NSView*)cv { |
289 base::scoped_nsobject<NSView> contentView([cv retain]); | 312 base::scoped_nsobject<NSView> contentView([cv retain]); |
290 NSView* superview = [contentView superview]; | 313 NSView* superview = [contentView superview]; |
291 [contentView removeFromSuperview]; | 314 [contentView removeFromSuperview]; |
292 [superview addSubview:contentView positioned:NSWindowBelow relativeTo:nil]; | 315 DCHECK(tabStripBackgroundView_); |
| 316 if (superview == [tabStripBackgroundView_ superview]) { |
| 317 [superview addSubview:contentView |
| 318 positioned:NSWindowAbove |
| 319 relativeTo:tabStripBackgroundView_]; |
| 320 } else { |
| 321 [superview addSubview:contentView positioned:NSWindowBelow relativeTo:nil]; |
| 322 } |
293 } | 323 } |
294 | 324 |
295 - (void)insertTabStripView:(NSView*)tabStripView intoWindow:(NSWindow*)window { | 325 - (void)insertTabStripView:(NSView*)tabStripView intoWindow:(NSWindow*)window { |
296 NSView* contentParent = [window cr_windowView]; | 326 NSView* contentParent = [window cr_windowView]; |
297 if (contentParent == [[window contentView] superview]) { | 327 if (contentParent == [[window contentView] superview]) { |
298 // Add the tab strip directly above the content view, if they are siblings. | 328 // Add the tab strip directly above the content view, if they are siblings. |
299 [contentParent addSubview:tabStripView | 329 [contentParent addSubview:tabStripView |
300 positioned:NSWindowAbove | 330 positioned:NSWindowAbove |
301 relativeTo:[window contentView]]; | 331 relativeTo:[window contentView]]; |
302 } else { | 332 } else { |
303 [contentParent addSubview:tabStripView]; | 333 [contentParent addSubview:tabStripView]; |
304 } | 334 } |
305 } | 335 } |
306 | 336 |
307 // Called when the size of the window content area has changed. Override to | 337 // Called when the size of the window content area has changed. Override to |
308 // position specific views. Base class implementation does nothing. | 338 // position specific views. Base class implementation does nothing. |
309 - (void)layoutSubviews { | 339 - (void)layoutSubviews { |
310 NOTIMPLEMENTED(); | 340 NOTIMPLEMENTED(); |
311 } | 341 } |
312 | 342 |
313 @end | 343 @end |
OLD | NEW |