OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_window_utils.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 [[NSRunLoop currentRunLoop] | 139 [[NSRunLoop currentRunLoop] |
140 performSelector:@selector(setTitle:) | 140 performSelector:@selector(setTitle:) |
141 target:window | 141 target:window |
142 argument:newTitle | 142 argument:newTitle |
143 order:0 | 143 order:0 |
144 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]]; | 144 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]]; |
145 return [newTitle copy]; | 145 return [newTitle copy]; |
146 } | 146 } |
147 | 147 |
148 // Our patterns want to be drawn from the upper left hand corner of the view. | 148 // The titlebar/tabstrip header on the mac is slightly smaller than on Windows. |
149 // Cocoa wants to do it from the lower left of the window. | 149 // There is also no window frame to the left and right of the web contents on |
| 150 // mac. |
| 151 // To keep: |
| 152 // - the window background pattern (IDR_THEME_FRAME.*) lined up vertically with |
| 153 // the tab and toolbar patterns |
| 154 // - the toolbar pattern lined up horizontally with the NTP background. |
| 155 // we have to shift the pattern slightly, rather than drawing from the top left |
| 156 // corner of the frame / tabstrip. The offsets below were empirically determined |
| 157 // in order to line these patterns up. |
150 // | 158 // |
151 // Rephase our pattern to fit this view. Some other views (Tabs, Toolbar etc.) | 159 // This will make the themes look slightly different than in Windows/Linux |
152 // will phase their patterns relative to this so all the views look right. | 160 // because of the differing heights between window top and tab top, but this has |
153 // | 161 // been approved by UI. |
154 // To line up the background pattern with the pattern in the browser window | |
155 // the background pattern for the tabs needs to be moved left by 5 pixels. | |
156 const CGFloat kPatternHorizontalOffset = -5; | 162 const CGFloat kPatternHorizontalOffset = -5; |
157 // To match Windows and CrOS, have to offset vertically by 2 pixels. | |
158 // Without tab strip, offset an extra pixel (determined by experimentation). | 163 // Without tab strip, offset an extra pixel (determined by experimentation). |
159 const CGFloat kPatternVerticalOffset = 2; | 164 const CGFloat kPatternVerticalOffset = 2; |
160 const CGFloat kPatternVerticalOffsetNoTabStrip = 3; | 165 const CGFloat kPatternVerticalOffsetNoTabStrip = 3; |
161 | 166 |
| 167 + (NSPoint)themeImagePositionFor:(NSView*)windowView |
| 168 withTabStrip:(NSView*)tabStripView |
| 169 alignment:(ThemeImageAlignment)alignment { |
| 170 if (!tabStripView) { |
| 171 return NSMakePoint(kPatternHorizontalOffset, |
| 172 NSHeight([windowView bounds]) + |
| 173 kPatternVerticalOffsetNoTabStrip); |
| 174 } |
162 | 175 |
163 + (NSPoint)themePatternPhaseFor:(NSView*)windowView | 176 NSPoint position = |
164 withTabStrip:(NSView*)tabStripView { | 177 [BrowserWindowUtils themeImagePositionInTabStripCoords:tabStripView |
165 // When we have a tab strip, line up with the top of the tab, otherwise, | 178 alignment:alignment]; |
166 // line up with the top of the window. | 179 return [tabStripView convertPoint:position toView:windowView]; |
167 if (!tabStripView) | 180 } |
| 181 |
| 182 + (NSPoint)themeImagePositionInTabStripCoords:(NSView*)tabStripView |
| 183 alignment:(ThemeImageAlignment)alignment { |
| 184 DCHECK(tabStripView); |
| 185 |
| 186 if (alignment == THEME_IMAGE_ALIGN_WITH_TAB_STRIP) { |
| 187 // The theme image is lined up with the top of the tab which is below the |
| 188 // top of the tab strip. |
168 return NSMakePoint(kPatternHorizontalOffset, | 189 return NSMakePoint(kPatternHorizontalOffset, |
169 NSHeight([windowView bounds]) | 190 [TabStripController defaultTabHeight] + |
170 + kPatternVerticalOffsetNoTabStrip); | 191 kPatternVerticalOffset); |
171 | 192 } |
172 NSRect tabStripViewWindowBounds = [tabStripView bounds]; | 193 // The theme image is lined up with the top of the tab strip (as opposed to |
173 tabStripViewWindowBounds = | 194 // the top of the tab above). This is the same as lining up with the top of |
174 [tabStripView convertRect:tabStripViewWindowBounds | 195 // the window's root view when not in presentation mode. |
175 toView:windowView]; | 196 return NSMakePoint(kPatternHorizontalOffset, |
176 return NSMakePoint(NSMinX(tabStripViewWindowBounds) | 197 NSHeight([tabStripView bounds]) + |
177 + kPatternHorizontalOffset, | 198 kPatternVerticalOffsetNoTabStrip); |
178 NSMinY(tabStripViewWindowBounds) | |
179 + [TabStripController defaultTabHeight] | |
180 + kPatternVerticalOffset); | |
181 } | 199 } |
182 | 200 |
183 + (void)activateWindowForController:(NSWindowController*)controller { | 201 + (void)activateWindowForController:(NSWindowController*)controller { |
184 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to | 202 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to |
185 // properly activate windows if Chrome is not the active application. | 203 // properly activate windows if Chrome is not the active application. |
186 [[controller window] makeKeyAndOrderFront:controller]; | 204 [[controller window] makeKeyAndOrderFront:controller]; |
187 ProcessSerialNumber psn; | 205 ProcessSerialNumber psn; |
188 GetCurrentProcess(&psn); | 206 GetCurrentProcess(&psn); |
189 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); | 207 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); |
190 } | 208 } |
191 | 209 |
192 @end | 210 @end |
OLD | NEW |