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

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: Fix interaction with tabStripBackgroundView. Add tests. 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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 themeImagePositionForAlignment:alignment]; 42 themeImagePositionForAlignment:alignment];
43 } 43 }
44 return NSZeroPoint; 44 return NSZeroPoint;
45 } 45 }
46 46
47 @end 47 @end
48 48
49 @implementation TabWindowController 49 @implementation TabWindowController
50 50
51 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip { 51 - (id)initTabWindowControllerWithTabStrip:(BOOL)hasTabStrip {
52 NSRect contentRect = NSMakeRect(60, 229, 750, 600); 52 const CGFloat kDefaultWidth = 750;
53 const CGFloat kDefaultHeight = 600;
54
55 NSRect contentRect = NSMakeRect(60, 229, kDefaultWidth, kDefaultHeight);
53 base::scoped_nsobject<FramedBrowserWindow> window( 56 base::scoped_nsobject<FramedBrowserWindow> window(
54 [[FramedBrowserWindow alloc] initWithContentRect:contentRect 57 [[FramedBrowserWindow alloc] initWithContentRect:contentRect
55 hasTabStrip:hasTabStrip]); 58 hasTabStrip:hasTabStrip]);
56 [window setReleasedWhenClosed:YES]; 59 [window setReleasedWhenClosed:YES];
57 [window setAutorecalculatesKeyViewLoop:YES]; 60 [window setAutorecalculatesKeyViewLoop:YES];
58 61
59 if ((self = [super initWithWindow:window])) { 62 if ((self = [super initWithWindow:window])) {
60 [[self window] setDelegate:self]; 63 [[self window] setDelegate:self];
61 64
62 tabContentArea_.reset([[FastResizeView alloc] initWithFrame: 65 chromeContentView_.reset([[NSView alloc]
63 NSMakeRect(0, 0, 750, 600)]); 66 initWithFrame:NSMakeRect(0, 0, kDefaultWidth, kDefaultHeight)]);
67 [chromeContentView_
68 setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
69 [chromeContentView_ setWantsLayer:YES];
70 [[[self window] contentView] addSubview:chromeContentView_];
71
72 tabContentArea_.reset(
73 [[FastResizeView alloc] initWithFrame:[chromeContentView_ bounds]]);
64 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable | 74 [tabContentArea_ setAutoresizingMask:NSViewWidthSizable |
65 NSViewHeightSizable]; 75 NSViewHeightSizable];
66 [[[self window] contentView] addSubview:tabContentArea_]; 76 [chromeContentView_ addSubview:tabContentArea_];
67 77
68 // tabStripBackgroundView_ draws the theme image behind the tab strip area. 78 // tabStripBackgroundView_ draws the theme image behind the tab strip area.
69 // When making a tab dragging window (setUseOverlay:), this view stays in 79 // 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 80 // the parent window so that it can be translucent, while the tab strip view
71 // moves to the child window and stays opaque. 81 // moves to the child window and stays opaque.
72 NSView* windowView = [window cr_windowView]; 82 NSView* windowView = [window cr_windowView];
73 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc] 83 tabStripBackgroundView_.reset([[TabStripBackgroundView alloc]
74 initWithFrame:NSMakeRect(0, 84 initWithFrame:NSMakeRect(0,
75 NSMaxY([windowView bounds]) - 85 NSMaxY([windowView bounds]) -
76 kBrowserFrameViewPaintHeight, 86 kBrowserFrameViewPaintHeight,
77 NSWidth([windowView bounds]), 87 NSWidth([windowView bounds]),
78 kBrowserFrameViewPaintHeight)]); 88 kBrowserFrameViewPaintHeight)]);
79 [tabStripBackgroundView_ 89 [tabStripBackgroundView_
80 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; 90 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
81 [windowView addSubview:tabStripBackgroundView_ 91 [self insertTabStripBackgroundViewIntoWindow:window];
erikchen 2014/10/09 21:24:39 It's unclear that tabStripBackgroundView should be
82 positioned:NSWindowBelow
83 relativeTo:nil];
84 92
85 [self moveContentViewToBack:[window contentView]]; 93 [self moveContentViewToBack:[window contentView]];
86 94
87 tabStripView_.reset([[TabStripView alloc] 95 tabStripView_.reset([[TabStripView alloc]
88 initWithFrame:NSMakeRect(0, 0, 750, chrome::kTabStripHeight)]); 96 initWithFrame:NSMakeRect(
97 0, 0, kDefaultWidth, chrome::kTabStripHeight)]);
89 [tabStripView_ setAutoresizingMask:NSViewWidthSizable | 98 [tabStripView_ setAutoresizingMask:NSViewWidthSizable |
90 NSViewMinYMargin]; 99 NSViewMinYMargin];
91 if (hasTabStrip) 100 if (hasTabStrip)
92 [self insertTabStripView:tabStripView_ intoWindow:[self window]]; 101 [self insertTabStripView:tabStripView_ intoWindow:[self window]];
93 } 102 }
94 return self; 103 return self;
95 } 104 }
96 105
97 - (NSView*)tabStripBackgroundView { 106 - (NSView*)tabStripBackgroundView {
98 return tabStripBackgroundView_; 107 return tabStripBackgroundView_;
99 } 108 }
100 109
101 - (TabStripView*)tabStripView { 110 - (TabStripView*)tabStripView {
102 return tabStripView_; 111 return tabStripView_;
103 } 112 }
104 113
105 - (FastResizeView*)tabContentArea { 114 - (FastResizeView*)tabContentArea {
106 return tabContentArea_; 115 return tabContentArea_;
107 } 116 }
108 117
118 - (NSView*)chromeContentView {
119 return chromeContentView_;
120 }
121
109 - (void)removeOverlay { 122 - (void)removeOverlay {
110 [self setUseOverlay:NO]; 123 [self setUseOverlay:NO];
111 if (closeDeferred_) { 124 if (closeDeferred_) {
112 // See comment in BrowserWindowCocoa::Close() about orderOut:. 125 // See comment in BrowserWindowCocoa::Close() about orderOut:.
113 [[self window] orderOut:self]; 126 [[self window] orderOut:self];
114 [[self window] performClose:self]; // Autoreleases the controller. 127 [[self window] performClose:self]; // Autoreleases the controller.
115 } 128 }
116 } 129 }
117 130
118 - (void)showOverlay { 131 - (void)showOverlay {
(...skipping 15 matching lines...) Expand all
134 147
135 overlayWindow_ = [[TabWindowOverlayWindow alloc] 148 overlayWindow_ = [[TabWindowOverlayWindow alloc]
136 initWithContentRect:[window frame] 149 initWithContentRect:[window frame]
137 styleMask:NSBorderlessWindowMask 150 styleMask:NSBorderlessWindowMask
138 backing:NSBackingStoreBuffered 151 backing:NSBackingStoreBuffered
139 defer:YES]; 152 defer:YES];
140 [overlayWindow_ setTitle:@"overlay"]; 153 [overlayWindow_ setTitle:@"overlay"];
141 [overlayWindow_ setBackgroundColor:[NSColor clearColor]]; 154 [overlayWindow_ setBackgroundColor:[NSColor clearColor]];
142 [overlayWindow_ setOpaque:NO]; 155 [overlayWindow_ setOpaque:NO];
143 [overlayWindow_ setDelegate:self]; 156 [overlayWindow_ setDelegate:self];
157 [[overlayWindow_ contentView] setWantsLayer:YES];
144 158
145 originalContentView_ = [window contentView]; 159 originalContentView_ = self.chromeContentView;
146 [window addChildWindow:overlayWindow_ ordered:NSWindowAbove]; 160 [window addChildWindow:overlayWindow_ ordered:NSWindowAbove];
147 161
148 // Explicitly set the responder to be nil here (for restoring later). 162 // Explicitly set the responder to be nil here (for restoring later).
149 // If the first responder were to be left non-nil here then 163 // If the first responder were to be left non-nil here then
150 // [RenderWidgethostViewCocoa resignFirstResponder] would be called, 164 // [RenderWidgethostViewCocoa resignFirstResponder] would be called,
151 // followed by RenderWidgetHost::Blur(), which would result in an unexpected 165 // followed by RenderWidgetHost::Blur(), which would result in an unexpected
152 // loss of focus. 166 // loss of focus.
153 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]); 167 focusBeforeOverlay_.reset([[FocusTracker alloc] initWithWindow:window]);
154 [window makeFirstResponder:nil]; 168 [window makeFirstResponder:nil];
155 169
156 // Move the original window's tab strip view and content view to the overlay 170 // 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 171 // window. The content view is added as a subview of the overlay window's
158 // content view (rather than using setContentView:) because the overlay 172 // content view (rather than using setContentView:) because the overlay
159 // window has a different content size (due to it being borderless). 173 // window has a different content size (due to it being borderless).
160 [[overlayWindow_ cr_windowView] addSubview:[self tabStripView]]; 174 [[overlayWindow_ cr_windowView] addSubview:[self tabStripView]];
161 [[overlayWindow_ contentView] addSubview:originalContentView_]; 175 [[overlayWindow_ contentView] addSubview:originalContentView_];
162 176
163 [overlayWindow_ orderFront:nil]; 177 [overlayWindow_ orderFront:nil];
164 } else if (!useOverlay && overlayWindow_) { 178 } else if (!useOverlay && overlayWindow_) {
165 DCHECK(originalContentView_); 179 DCHECK(originalContentView_);
166 180
167 // Return the original window's tab strip view and content view to their 181 // 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 182 // 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 183 // content view and therefore it should always be added after the content
170 // view is set. 184 // view is set.
171 [window setContentView:originalContentView_]; 185 [[window contentView] addSubview:originalContentView_
172 [self moveContentViewToBack:originalContentView_]; 186 positioned:NSWindowBelow
187 relativeTo:nil];
188 originalContentView_.frame = [[window contentView] bounds];
173 [self insertTabStripView:[self tabStripView] intoWindow:window]; 189 [self insertTabStripView:[self tabStripView] intoWindow:window];
174 [[window cr_windowView] updateTrackingAreas]; 190 [[window cr_windowView] updateTrackingAreas];
175 191
176 [focusBeforeOverlay_ restoreFocusInWindow:window]; 192 [focusBeforeOverlay_ restoreFocusInWindow:window];
177 focusBeforeOverlay_.reset(); 193 focusBeforeOverlay_.reset();
178 194
179 [window display]; 195 [window display];
180 [window removeChildWindow:overlayWindow_]; 196 [window removeChildWindow:overlayWindow_];
181 197
182 [overlayWindow_ orderOut:nil]; 198 [overlayWindow_ orderOut:nil];
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (contentParent == [[window contentView] superview]) { 343 if (contentParent == [[window contentView] superview]) {
328 // Add the tab strip directly above the content view, if they are siblings. 344 // Add the tab strip directly above the content view, if they are siblings.
329 [contentParent addSubview:tabStripView 345 [contentParent addSubview:tabStripView
330 positioned:NSWindowAbove 346 positioned:NSWindowAbove
331 relativeTo:[window contentView]]; 347 relativeTo:[window contentView]];
332 } else { 348 } else {
333 [contentParent addSubview:tabStripView]; 349 [contentParent addSubview:tabStripView];
334 } 350 }
335 } 351 }
336 352
353 - (void)insertTabStripBackgroundViewIntoWindow:(NSWindow*)window {
354 DCHECK(tabStripBackgroundView_);
355 NSView* rootView = [[window contentView] superview];
356 [rootView addSubview:tabStripBackgroundView_
357 positioned:NSWindowBelow
358 relativeTo:nil];
359 }
360
337 // Called when the size of the window content area has changed. Override to 361 // Called when the size of the window content area has changed. Override to
338 // position specific views. Base class implementation does nothing. 362 // position specific views. Base class implementation does nothing.
339 - (void)layoutSubviews { 363 - (void)layoutSubviews {
340 NOTIMPLEMENTED(); 364 NOTIMPLEMENTED();
341 } 365 }
342 366
343 @end 367 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698