Chromium Code Reviews| 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 of the web contents on mac. |
| 150 // To keep: | |
| 151 // - the window background pattern (IDR_THEME_FRAME.*) lined up vertically with | |
| 152 // the tab and toolbar patterns | |
| 153 // - the toolbar pattern lined up horizontally with the NTP background. | |
| 154 // we have to shift the pattern slightly, rather than drawing from the top left | |
| 155 // corner of the frame / tabstrip. The offsets below were empirically determined | |
| 156 // in order to line these patterns up. | |
| 150 // | 157 // |
| 151 // Rephase our pattern to fit this view. Some other views (Tabs, Toolbar etc.) | 158 // 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. | 159 // because of the differing heights between window top and tab top, but this has |
| 153 // | 160 // 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; | 161 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). | 162 // Without tab strip, offset an extra pixel (determined by experimentation). |
| 159 const CGFloat kPatternVerticalOffset = 2; | 163 const CGFloat kPatternVerticalOffset = 2; |
| 160 const CGFloat kPatternVerticalOffsetNoTabStrip = 3; | 164 const CGFloat kPatternVerticalOffsetNoTabStrip = 3; |
| 161 | 165 |
| 166 + (NSPoint)themeImagePositionFor:(NSView*)windowView | |
| 167 withTabStrip:(NSView*)tabStripView | |
| 168 alignment:(ThemeImageAlignment)alignment { | |
| 169 if (!tabStripView) { | |
| 170 return NSMakePoint(kPatternHorizontalOffset, | |
| 171 NSHeight([windowView bounds]) + | |
| 172 kPatternVerticalOffsetNoTabStrip); | |
| 173 } | |
| 162 | 174 |
| 163 + (NSPoint)themePatternPhaseFor:(NSView*)windowView | 175 NSPoint position = |
| 164 withTabStrip:(NSView*)tabStripView { | 176 [BrowserWindowUtils themeImagePositionInTabStripCoords:tabStripView |
| 165 // When we have a tab strip, line up with the top of the tab, otherwise, | 177 alignment:alignment]; |
| 166 // line up with the top of the window. | 178 return [tabStripView convertPoint:position toView:windowView]; |
| 167 if (!tabStripView) | 179 } |
| 180 | |
| 181 + (NSPoint) themeImagePositionInTabStripCoords:(NSView*)tabStripView | |
|
Robert Sesek
2013/07/30 14:25:24
nit: no space after )
| |
| 182 alignment:(ThemeImageAlignment)alignment { | |
| 183 DCHECK(tabStripView); | |
| 184 | |
| 185 if (alignment == THEME_IMAGE_ALIGN_WITH_TAB_STRIP) { | |
| 186 // The theme image is lined up with the top of the tab which is below the | |
| 187 // top of the tab strip. | |
| 168 return NSMakePoint(kPatternHorizontalOffset, | 188 return NSMakePoint(kPatternHorizontalOffset, |
| 169 NSHeight([windowView bounds]) | 189 [TabStripController defaultTabHeight] + |
| 170 + kPatternVerticalOffsetNoTabStrip); | 190 kPatternVerticalOffset); |
| 171 | 191 } |
| 172 NSRect tabStripViewWindowBounds = [tabStripView bounds]; | 192 // The theme image is lined up with the top of the tab strip (as opposed to |
| 173 tabStripViewWindowBounds = | 193 // the top of the tab above). This is the same as lining up with the top of |
| 174 [tabStripView convertRect:tabStripViewWindowBounds | 194 // the window's root view when not in presentation mode. |
| 175 toView:windowView]; | 195 return NSMakePoint(kPatternHorizontalOffset, |
| 176 return NSMakePoint(NSMinX(tabStripViewWindowBounds) | 196 NSHeight([tabStripView bounds]) + |
| 177 + kPatternHorizontalOffset, | 197 kPatternVerticalOffsetNoTabStrip); |
| 178 NSMinY(tabStripViewWindowBounds) | |
| 179 + [TabStripController defaultTabHeight] | |
| 180 + kPatternVerticalOffset); | |
| 181 } | 198 } |
| 182 | 199 |
| 183 + (void)activateWindowForController:(NSWindowController*)controller { | 200 + (void)activateWindowForController:(NSWindowController*)controller { |
| 184 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to | 201 // 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. | 202 // properly activate windows if Chrome is not the active application. |
| 186 [[controller window] makeKeyAndOrderFront:controller]; | 203 [[controller window] makeKeyAndOrderFront:controller]; |
| 187 ProcessSerialNumber psn; | 204 ProcessSerialNumber psn; |
| 188 GetCurrentProcess(&psn); | 205 GetCurrentProcess(&psn); |
| 189 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); | 206 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); |
| 190 } | 207 } |
| 191 | 208 |
| 192 @end | 209 @end |
| OLD | NEW |