Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(867)

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_window_controller.mm

Issue 646703002: mac: Use a full-size content view (reland 1). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from avi. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_background_view.h"
12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
13 #import "chrome/browser/ui/cocoa/themed_window.h" 13 #import "chrome/browser/ui/cocoa/themed_window.h"
14 #import "chrome/browser/ui/cocoa/version_independent_window.h" 14 #import "chrome/browser/ui/cocoa/version_independent_window.h"
15 #import "ui/base/cocoa/focus_tracker.h" 15 #import "ui/base/cocoa/focus_tracker.h"
16 #include "ui/base/theme_provider.h" 16 #include "ui/base/theme_provider.h"
17 17
18 @interface TabWindowController(PRIVATE) 18 @interface TabWindowController ()
19 - (void)setUseOverlay:(BOOL)useOverlay; 19 - (void)setUseOverlay:(BOOL)useOverlay;
20
21 // The tab strip background view should always be inserted as the back-most
22 // subview of the root view. It cannot be a subview of the contentView, as that
23 // would cause it to become layer backed, which would cause it to draw on top
24 // of non-layer backed content like the window controls.
25 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window;
20 @end 26 @end
21 27
22 @interface TabWindowOverlayWindow : NSWindow 28 @interface TabWindowOverlayWindow : NSWindow
23 @end 29 @end
24 30
25 @implementation TabWindowOverlayWindow 31 @implementation TabWindowOverlayWindow
26 32
27 - (ui::ThemeProvider*)themeProvider { 33 - (ui::ThemeProvider*)themeProvider {
28 if ([self parentWindow]) 34 if ([self parentWindow])
29 return [[[self parentWindow] windowController] themeProvider]; 35 return [[[self parentWindow] windowController] themeProvider];
(...skipping 12 matching lines...) Expand all
42 themeImagePositionForAlignment:alignment]; 48 themeImagePositionForAlignment:alignment];
43 } 49 }
44 return NSZeroPoint; 50 return NSZeroPoint;
45 } 51 }
46 52
47 @end 53 @end
48 54
49 @implementation TabWindowController 55 @implementation TabWindowController
50 56
51 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip { 57 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip {
52 NSRect contentRect = NSMakeRect(60, 229, 750, 600); 58 const CGFloat kDefaultWidth = 750;
59 const CGFloat kDefaultHeight = 600;
60
61 NSRect contentRect = NSMakeRect(60, 229, kDefaultWidth, kDefaultHeight);
53 base::scoped_nsobject<FramedBrowserWindow> window( 62 base::scoped_nsobject<FramedBrowserWindow> window(
54 [[FramedBrowserWindow alloc] initWithContentRect:contentRect 63 [[FramedBrowserWindow alloc] initWithContentRect:contentRect
55 hasTabStrip:hasTabStrip]); 64 hasTabStrip:hasTabStrip]);
56 [window setReleasedWhenClosed:YES]; 65 [window setReleasedWhenClosed:YES];
57 [window setAutorecalculatesKeyViewLoop:YES]; 66 [window setAutorecalculatesKeyViewLoop:YES];
58 67
59 if ((self = [super initWithWindow:window])) { 68 if ((self = [super initWithWindow:window])) {
60 [[self window] setDelegate:self]; 69 [[self window] setDelegate:self];
61 70
62 tabContentArea_.reset([[FastResizeView alloc] initWithFrame: 71 chromeContentView_.reset([[NSView alloc]
63 NSMakeRect(0, 0, 750, 600)]); 72 initWithFrame:NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight)]);
73 [chromeContentView_
74 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
75 [chromeContentView_ setWantsLayer:YES];
76 [[[self window] contentView] addSubview:chromeContentView_];
77
78 tabContentArea_.reset(
79 [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]);
64 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | 80 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable |
65 NSViewHeightSizable]; 81 NSViewHeightSizable];
66 [[[self window] contentView] addSubview:tabContentArea_]; 82 [chromeContentView_ addSubview:tabContentArea_];
67 83
68 // tabStripBackgroundView_ draws the theme image behind the tab strip area. 84 // tabStripBackgroundView_ draws the theme image behind the tab strip area.
69 // When making a tab dragging window (setUseOverlay:), this view stays in 85 // 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 86 // the parent window so that it can be translucent, while the tab strip view
71 // moves to the child window and stays opaque. 87 // moves to the child window and stays opaque.
72 NSView* windowView = [window cr_windowView]; 88 NSView* windowView = [window cr_windowView];
73 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] 89 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc]
74 initWithFrame:NSMakeRect(0, 90 initWithFrame:NSMakeRect(0,
75 NSMaxY([windowView bounds]) - 91 NSMaxY([windowView bounds]) -
76 kBrowserFrameViewPaintHeight, 92 kBrowserFrameViewPaintHeight,
77 NSWidth([windowView bounds]), 93 NSWidth([windowView bounds]),
78 kBrowserFrameViewPaintHeight)]); 94 kBrowserFrameViewPaintHeight)]);
79 [tabStripBackgroundView_ 95 [tabStripBackgroundView_
80 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; 96 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
81 [windowView addSubview:tabStripBackgroundView_ 97 [self insertTabStripBackgroundViewIntoWindow:window];
82 positioned:NSWindowBelow
83 relativeTo:nil];
84 98
85 [self moveContentViewToBack:[window contentView]]; 99 [self moveContentViewToBack:[window contentView]];
86 100
87 tabStripView_.reset([[TabStripView alloc] 101 tabStripView_.reset([[TabStripView alloc]
88 initWithFrame:NSMakeRect(0, 0, 750, chrome::kTabStripHeight)]); 102 initWithFrame:NSMakeRect(
103 0, 0, kDefaultWidth, chrome::kTabStripHeight)]);
89 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | 104 [tabStripView_ setAutoresizingMask:NSViewWidthSizable |
90 NSViewMinYMargin]; 105 NSViewMinYMargin];
91 if (hasTabStrip) 106 if (hasTabStrip)
92 [self insertTabStripView:tabStripView_ intoWindow:[self window]]; 107 [self insertTabStripView:tabStripView_ intoWindow:[self window]];
93 } 108 }
94 return self; 109 return self;
95 } 110 }
96 111
97 - (NSView*)tabStripBackgroundView { 112 - (NSView*)tabStripBackgroundView {
98 return tabStripBackgroundView_; 113 return tabStripBackgroundView_;
99 } 114 }
100 115
101 - (TabStripView*)tabStripView { 116 - (TabStripView*)tabStripView {
102 return tabStripView_; 117 return tabStripView_;
103 } 118 }
104 119
105 - (FastResizeView*)tabContentArea { 120 - (FastResizeView*)tabContentArea {
106 return tabContentArea_; 121 return tabContentArea_;
107 } 122 }
108 123
124 - (NSView*)chromeContentView {
125 return chromeContentView_;
126 }
127
109 - (void)removeOverlay { 128 - (void)removeOverlay {
110 [self setUseOverlay:NO]; 129 [self setUseOverlay:NO];
111 if (closeDeferred_) { 130 if (closeDeferred_) {
112 // See comment in BrowserWindowCocoa::Close() about orderOut:. 131 // See comment in BrowserWindowCocoa::Close() about orderOut:.
113 [[self window] orderOut:self]; 132 [[self window] orderOut:self];
114 [[self window] performClose:self]; // Autoreleases the controller. 133 [[self window] performClose:self]; // Autoreleases the controller.
115 } 134 }
116 } 135 }
117 136
118 - (void)showOverlay { 137 - (void)showOverlay {
(...skipping 15 matching lines...) Expand all
134 153
135 overlayWindow_ = [[TabWindowOverlayWindow alloc] 154 overlayWindow_ = [[TabWindowOverlayWindow alloc]
136 initWithContentRect:[window frame] 155 initWithContentRect:[window frame]
137 styleMask:NSBorderlessWindowMask 156 styleMask:NSBorderlessWindowMask
138 backing:NSBackingStoreBuffered 157 backing:NSBackingStoreBuffered
139 defer:YES]; 158 defer:YES];
140 [overlayWindow_ setTitle:@"overlay"]; 159 [overlayWindow_ setTitle:@"overlay"];
141 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; 160 [overlayWindow_ setBackgroundColor:[NSColor clearColor]];
142 [overlayWindow_ setOpaque:NO]; 161 [overlayWindow_ setOpaque:NO];
143 [overlayWindow_ setDelegate:self]; 162 [overlayWindow_ setDelegate:self];
163 [[overlayWindow_ contentView] setWantsLayer:YES];
144 164
145 originalContentView_ = [window contentView]; 165 originalContentView_ = self.chromeContentView;
146 [window addChildWindow:overlayWindow_ ordered:NSWindowAbove]; 166 [window addChildWindow:overlayWindow_ ordered:NSWindowAbove];
147 167
148 // Explicitly set the responder to be nil here (for restoring later). 168 // Explicitly set the responder to be nil here (for restoring later).
149 // If the first responder were to be left non-nil here then 169 // If the first responder were to be left non-nil here then
150 // [RenderWidgethostViewCocoa resignFirstResponder] would be called, 170 // [RenderWidgethostViewCocoa resignFirstResponder] would be called,
151 // followed by RenderWidgetHost::Blur(), which would result in an unexpected 171 // followed by RenderWidgetHost::Blur(), which would result in an unexpected
152 // loss of focus. 172 // loss of focus.
153 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]); 173 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]);
154 [window makeFirstResponder:nil]; 174 [window makeFirstResponder:nil];
155 175
156 // Move the original window's tab strip view and content view to the overlay 176 // Move the original window's tab strip view and content view to the overlay
157 // window. The content view is added as a subview of the overlay window's 177 // window. The content view is added as a subview of the overlay window's
158 // content view (rather than using setContentView:) because the overlay 178 // content view (rather than using setContentView:) because the overlay
159 // window has a different content size (due to it being borderless). 179 // window has a different content size (due to it being borderless).
160 [[overlayWindow_ cr_windowView] addSubview:[self tabStripView]]; 180 [[overlayWindow_ cr_windowView] addSubview:[self tabStripView]];
161 [[overlayWindow_ contentView] addSubview:originalContentView_]; 181 [[overlayWindow_ contentView] addSubview:originalContentView_];
162 182
163 [overlayWindow_ orderFront:nil]; 183 [overlayWindow_ orderFront:nil];
164 } else if (!useOverlay && overlayWindow_) { 184 } else if (!useOverlay && overlayWindow_) {
165 DCHECK(originalContentView_); 185 DCHECK(originalContentView_);
166 186
167 // Return the original window's tab strip view and content view to their 187 // Return the original window's tab strip view and content view to their
168 // places. The TabStripView always needs to be in front of the window's 188 // places. The TabStripView always needs to be in front of the window's
169 // content view and therefore it should always be added after the content 189 // content view and therefore it should always be added after the content
170 // view is set. 190 // view is set.
171 [window setContentView:originalContentView_]; 191 [[window contentView] addSubview:originalContentView_
172 [self moveContentViewToBack:originalContentView_]; 192 positioned:NSWindowBelow
193 relativeTo:nil];
194 originalContentView_.frame = [[window contentView] bounds];
173 [self insertTabStripView:[self tabStripView] intoWindow:window]; 195 [self insertTabStripView:[self tabStripView] intoWindow:window];
174 [[window cr_windowView] updateTrackingAreas]; 196 [[window cr_windowView] updateTrackingAreas];
175 197
176 [focusBeforeOverlay_ restoreFocusInWindow:window]; 198 [focusBeforeOverlay_ restoreFocusInWindow:window];
177 focusBeforeOverlay_.reset(); 199 focusBeforeOverlay_.reset();
178 200
179 [window display]; 201 [window display];
180 [window removeChildWindow:overlayWindow_]; 202 [window removeChildWindow:overlayWindow_];
181 203
182 [overlayWindow_ orderOut:nil]; 204 [overlayWindow_ orderOut:nil];
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (contentParent == [[window contentView] superview]) { 349 if (contentParent == [[window contentView] superview]) {
328 // Add the tab strip directly above the content view, if they are siblings. 350 // Add the tab strip directly above the content view, if they are siblings.
329 [contentParent addSubview:tabStripView 351 [contentParent addSubview:tabStripView
330 positioned:NSWindowAbove 352 positioned:NSWindowAbove
331 relativeTo:[window contentView]]; 353 relativeTo:[window contentView]];
332 } else { 354 } else {
333 [contentParent addSubview:tabStripView]; 355 [contentParent addSubview:tabStripView];
334 } 356 }
335 } 357 }
336 358
359 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window {
360 DCHECK(tabStripBackgroundView_);
361 NSView* rootView = [[window contentView] superview];
362 [rootView addSubview:tabStripBackgroundView_
363 positioned:NSWindowBelow
364 relativeTo:nil];
365 }
366
337 // Called when the size of the window content area has changed. Override to 367 // Called when the size of the window content area has changed. Override to
338 // position specific views. Base class implementation does nothing. 368 // position specific views. Base class implementation does nothing.
339 - (void)layoutSubviews { 369 - (void)layoutSubviews {
340 NOTIMPLEMENTED(); 370 NOTIMPLEMENTED();
341 } 371 }
342 372
343 @end 373 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_window_controller.h ('k') | chrome/browser/ui/cocoa/version_independent_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698