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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 9 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 11 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
12 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" | 12 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
| 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
13 #include "content/common/native_web_keyboard_event.h" | 14 #include "content/common/native_web_keyboard_event.h" |
14 | 15 |
15 @interface MenuWalker : NSObject | 16 @interface MenuWalker : NSObject |
16 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key | 17 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key |
17 menu:(NSMenu*)menu; | 18 menu:(NSMenu*)menu; |
18 @end | 19 @end |
19 | 20 |
20 @implementation MenuWalker | 21 @implementation MenuWalker |
21 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key | 22 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key |
22 menu:(NSMenu*)menu { | 23 menu:(NSMenu*)menu { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 if ([event_window handleExtraWindowKeyboardShortcut:event]) | 112 if ([event_window handleExtraWindowKeyboardShortcut:event]) |
112 return true; | 113 return true; |
113 | 114 |
114 if ([event_window handleDelayedWindowKeyboardShortcut:event]) | 115 if ([event_window handleDelayedWindowKeyboardShortcut:event]) |
115 return true; | 116 return true; |
116 } | 117 } |
117 | 118 |
118 return [event_window redispatchKeyEvent:event]; | 119 return [event_window redispatchKeyEvent:event]; |
119 } | 120 } |
120 | 121 |
| 122 + (void)delayedReplace:(NSString*)oldTitle |
| 123 with:(NSString*)newTitle |
| 124 on:(NSWindow*)window { |
| 125 if (oldTitle) |
| 126 [[NSRunLoop currentRunLoop] |
| 127 cancelPerformSelector:@selector(setTitle:) |
| 128 target:window |
| 129 argument:oldTitle]; |
| 130 |
| 131 [[NSRunLoop currentRunLoop] |
| 132 performSelector:@selector(setTitle:) |
| 133 target:window |
| 134 argument:newTitle |
| 135 order:0 |
| 136 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]]; |
| 137 } |
| 138 |
| 139 // Our patterns want to be drawn from the upper left hand corner of the view. |
| 140 // Cocoa wants to do it from the lower left of the window. |
| 141 // |
| 142 // Rephase our pattern to fit this view. Some other views (Tabs, Toolbar etc.) |
| 143 // will phase their patterns relative to this so all the views look right. |
| 144 // |
| 145 // To line up the background pattern with the pattern in the browser window |
| 146 // the background pattern for the tabs needs to be moved left by 5 pixels. |
| 147 const CGFloat kPatternHorizontalOffset = -5; |
| 148 // To match Windows and CrOS, have to offset vertically by 2 pixels. |
| 149 // Without tab strip, offset an extra pixel (determined by experimentation). |
| 150 const CGFloat kPatternVerticalOffset = 2; |
| 151 const CGFloat kPatternVerticalOffsetNoTabStrip = 3; |
| 152 |
| 153 |
| 154 + (NSPoint)themePatternPhaseFor:(NSView*)windowView |
| 155 withTabStrip:(NSView*)tabStripView { |
| 156 // When we have a tab strip, line up with the top of the tab, otherwise, |
| 157 // line up with the top of the window. |
| 158 if (!tabStripView) |
| 159 return NSMakePoint(kPatternHorizontalOffset, |
| 160 NSHeight([windowView bounds]) |
| 161 + kPatternVerticalOffsetNoTabStrip); |
| 162 |
| 163 NSRect tabStripViewWindowBounds = [tabStripView bounds]; |
| 164 tabStripViewWindowBounds = |
| 165 [tabStripView convertRect:tabStripViewWindowBounds |
| 166 toView:windowView]; |
| 167 return NSMakePoint(NSMinX(tabStripViewWindowBounds) |
| 168 + kPatternHorizontalOffset, |
| 169 NSMinY(tabStripViewWindowBounds) |
| 170 + [TabStripController defaultTabHeight] |
| 171 + kPatternVerticalOffset); |
| 172 } |
| 173 |
121 @end | 174 @end |
OLD | NEW |