| OLD | NEW |
| 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/framed_browser_window.h" | 5 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
| 9 #include "base/metrics/histogram.h" |
| 9 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 10 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 11 #include "chrome/browser/themes/theme_properties.h" | 12 #include "chrome/browser/themes/theme_properties.h" |
| 12 #include "chrome/browser/themes/theme_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
| 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 15 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 15 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 16 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/themed_window.h" | 17 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 18 #include "ui/base/cocoa/nsgraphics_context_additions.h" | 19 #include "ui/base/cocoa/nsgraphics_context_additions.h" |
| 19 #import "ui/base/cocoa/nsview_additions.h" | 20 #import "ui/base/cocoa/nsview_additions.h" |
| 20 | 21 |
| 21 // Implementer's note: Moving the window controls is tricky. When altering the | 22 // Implementer's note: Moving the window controls is tricky. When altering the |
| 22 // code, ensure that: | 23 // code, ensure that: |
| 23 // - accessibility hit testing works | 24 // - accessibility hit testing works |
| 24 // - the accessibility hierarchy is correct | 25 // - the accessibility hierarchy is correct |
| 25 // - close/min in the background don't bring the window forward | 26 // - close/min in the background don't bring the window forward |
| 26 // - rollover effects work correctly | 27 // - rollover effects work correctly |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // Size of the gradient. Empirically determined so that the gradient looks | 31 // Size of the gradient. Empirically determined so that the gradient looks |
| 31 // like what the heuristic does when there are just a few tabs. | 32 // like what the heuristic does when there are just a few tabs. |
| 32 const CGFloat kWindowGradientHeight = 24.0; | 33 const CGFloat kWindowGradientHeight = 24.0; |
| 33 | 34 |
| 35 enum FrameBrowserWindowLock { |
| 36 SET_FRAME_LOCKED = 0, |
| 37 SET_STYLEMASK_LOCKED = 1, |
| 38 FRAMEBROWSERWINDOWLOCKCOUNT = 2 |
| 39 }; |
| 40 |
| 41 void LogUMASample(FrameBrowserWindowLock sample) { |
| 42 UMA_HISTOGRAM_ENUMERATION("FramedBrowserWindowLock", sample, |
| 43 FRAMEBROWSERWINDOWLOCKCOUNT); |
| 34 } | 44 } |
| 35 | 45 |
| 46 } // namespace |
| 47 |
| 36 @interface FramedBrowserWindow (Private) | 48 @interface FramedBrowserWindow (Private) |
| 37 | 49 |
| 38 - (void)adjustCloseButton:(NSNotification*)notification; | 50 - (void)adjustCloseButton:(NSNotification*)notification; |
| 39 - (void)adjustMiniaturizeButton:(NSNotification*)notification; | 51 - (void)adjustMiniaturizeButton:(NSNotification*)notification; |
| 40 - (void)adjustZoomButton:(NSNotification*)notification; | 52 - (void)adjustZoomButton:(NSNotification*)notification; |
| 41 - (void)adjustButton:(NSButton*)button | 53 - (void)adjustButton:(NSButton*)button |
| 42 ofKind:(NSWindowButton)kind; | 54 ofKind:(NSWindowButton)kind; |
| 55 - (void)logUMASample:(FrameBrowserWindowLock)sample; |
| 43 | 56 |
| 44 @end | 57 @end |
| 45 | 58 |
| 46 @implementation FramedBrowserWindow | 59 @implementation FramedBrowserWindow |
| 47 | 60 |
| 61 - (void)setStyleMask:(NSUInteger)styleMask { |
| 62 if (frameAndStyleMaskLock_) { |
| 63 LogUMASample(FrameBrowserWindowLock::SET_FRAME_LOCKED); |
| 64 return; |
| 65 } |
| 66 [super setStyleMask:styleMask]; |
| 67 } |
| 68 |
| 69 - (void)setFrame:(NSRect)frameRect |
| 70 display:(BOOL)flag |
| 71 animate:(BOOL)animateFlag { |
| 72 if (frameAndStyleMaskLock_) { |
| 73 LogUMASample(FrameBrowserWindowLock::SET_STYLEMASK_LOCKED); |
| 74 return; |
| 75 } |
| 76 [super setFrame:frameRect display:flag animate:animateFlag]; |
| 77 } |
| 78 |
| 48 - (id)initWithContentRect:(NSRect)contentRect | 79 - (id)initWithContentRect:(NSRect)contentRect |
| 49 hasTabStrip:(BOOL)hasTabStrip{ | 80 hasTabStrip:(BOOL)hasTabStrip{ |
| 50 NSUInteger styleMask = NSTitledWindowMask | | 81 NSUInteger styleMask = NSTitledWindowMask | |
| 51 NSClosableWindowMask | | 82 NSClosableWindowMask | |
| 52 NSMiniaturizableWindowMask | | 83 NSMiniaturizableWindowMask | |
| 53 NSResizableWindowMask | | 84 NSResizableWindowMask | |
| 54 NSTexturedBackgroundWindowMask; | 85 NSTexturedBackgroundWindowMask; |
| 55 if ((self = [super initWithContentRect:contentRect | 86 if ((self = [super initWithContentRect:contentRect |
| 56 styleMask:styleMask | 87 styleMask:styleMask |
| 57 backing:NSBackingStoreBuffered | 88 backing:NSBackingStoreBuffered |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 name:NSViewFrameDidChangeNotification | 121 name:NSViewFrameDidChangeNotification |
| 91 object:closeButton_]; | 122 object:closeButton_]; |
| 92 [center addObserver:self | 123 [center addObserver:self |
| 93 selector:@selector(adjustMiniaturizeButton:) | 124 selector:@selector(adjustMiniaturizeButton:) |
| 94 name:NSViewFrameDidChangeNotification | 125 name:NSViewFrameDidChangeNotification |
| 95 object:miniaturizeButton_]; | 126 object:miniaturizeButton_]; |
| 96 [center addObserver:self | 127 [center addObserver:self |
| 97 selector:@selector(adjustZoomButton:) | 128 selector:@selector(adjustZoomButton:) |
| 98 name:NSViewFrameDidChangeNotification | 129 name:NSViewFrameDidChangeNotification |
| 99 object:zoomButton_]; | 130 object:zoomButton_]; |
| 131 |
| 132 frameAndStyleMaskLock_ = NO; |
| 100 } | 133 } |
| 101 | 134 |
| 102 return self; | 135 return self; |
| 103 } | 136 } |
| 104 | 137 |
| 105 - (void)dealloc { | 138 - (void)dealloc { |
| 106 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 139 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 107 [super dealloc]; | 140 [super dealloc]; |
| 108 } | 141 } |
| 109 | 142 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 if (!value) { | 203 if (!value) { |
| 171 value = [super accessibilityHitTest:point]; | 204 value = [super accessibilityHitTest:point]; |
| 172 } | 205 } |
| 173 return value; | 206 return value; |
| 174 } | 207 } |
| 175 | 208 |
| 176 - (void)setShouldHideTitle:(BOOL)flag { | 209 - (void)setShouldHideTitle:(BOOL)flag { |
| 177 shouldHideTitle_ = flag; | 210 shouldHideTitle_ = flag; |
| 178 } | 211 } |
| 179 | 212 |
| 213 // This method sets a lock which prevents the the frame and style |
| 214 // of the window to be changed |
| 215 - (void)setFrameAndStyleMaskLock:(BOOL)lock { |
| 216 frameAndStyleMaskLock_ = lock; |
| 217 } |
| 218 |
| 180 - (BOOL)_isTitleHidden { | 219 - (BOOL)_isTitleHidden { |
| 181 return shouldHideTitle_; | 220 return shouldHideTitle_; |
| 182 } | 221 } |
| 183 | 222 |
| 184 - (CGFloat)windowButtonsInterButtonSpacing { | 223 - (CGFloat)windowButtonsInterButtonSpacing { |
| 185 return windowButtonsInterButtonSpacing_; | 224 return windowButtonsInterButtonSpacing_; |
| 186 } | 225 } |
| 187 | 226 |
| 188 // This method is called whenever a window is moved in order to ensure it fits | 227 // This method is called whenever a window is moved in order to ensure it fits |
| 189 // on the screen. We cannot always handle resizes without breaking, so we | 228 // on the screen. We cannot always handle resizes without breaking, so we |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 ThemedWindowStyle windowStyle = [self themedWindowStyle]; | 377 ThemedWindowStyle windowStyle = [self themedWindowStyle]; |
| 339 BOOL incognito = windowStyle & THEMED_INCOGNITO; | 378 BOOL incognito = windowStyle & THEMED_INCOGNITO; |
| 340 | 379 |
| 341 if (incognito) | 380 if (incognito) |
| 342 return [NSColor whiteColor]; | 381 return [NSColor whiteColor]; |
| 343 else | 382 else |
| 344 return [NSColor windowFrameTextColor]; | 383 return [NSColor windowFrameTextColor]; |
| 345 } | 384 } |
| 346 | 385 |
| 347 @end | 386 @end |
| OLD | NEW |