| 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 "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 5 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 struct KeyFrame { | 70 struct KeyFrame { |
| 71 float value; | 71 float value; |
| 72 float scale; | 72 float scale; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Get the window location relative to the top left of the main screen. | 75 // Get the window location relative to the top left of the main screen. |
| 76 // Most Cocoa APIs use a coordinate system where the screen origin is the | 76 // Most Cocoa APIs use a coordinate system where the screen origin is the |
| 77 // bottom left. The various CGSSetWindow* APIs use a coordinate system where | 77 // bottom left. The various CGSSetWindow* APIs use a coordinate system where |
| 78 // the screen origin is the top left. | 78 // the screen origin is the top left. |
| 79 NSPoint GetCGSWindowScreenOrigin(NSWindow* window) { | 79 // NSPoint GetCGSWindowScreenOrigin(NSWindow* window) { |
| 80 NSArray* screens = [NSScreen screens]; | 80 // NSArray* screens = [NSScreen screens]; |
| 81 if ([screens count] == 0) | 81 // if ([screens count] == 0) |
| 82 return NSZeroPoint; | 82 // return NSZeroPoint; |
| 83 // Origin is relative to the screen with the menu bar (the screen at index 0). | 83 // // Origin is relative to the screen with the menu bar (the screen at index |
| 84 // Note, this is not the same as mainScreen which is the screen with the key | 84 // 0). |
| 85 // window. | 85 // // Note, this is not the same as mainScreen which is the screen with the |
| 86 NSScreen* main_screen = [screens objectAtIndex:0]; | 86 // key |
| 87 | 87 // // window. |
| 88 NSRect window_frame = [window frame]; | 88 // NSScreen* main_screen = [screens objectAtIndex:0]; |
| 89 NSRect screen_frame = [main_screen frame]; | 89 // |
| 90 return NSMakePoint(NSMinX(window_frame), | 90 // NSRect window_frame = [window frame]; |
| 91 NSHeight(screen_frame) - NSMaxY(window_frame)); | 91 // NSRect screen_frame = [main_screen frame]; |
| 92 } | 92 // return NSMakePoint(NSMinX(window_frame), |
| 93 // NSHeight(screen_frame) - NSMaxY(window_frame)); |
| 94 // } |
| 93 | 95 |
| 94 // Set the transparency of the window. | 96 // Set the transparency of the window. |
| 95 void SetWindowAlpha(NSWindow* window, float alpha) { | 97 void SetWindowAlpha(NSWindow* window, float alpha) { |
| 96 CGSConnection cid = _CGSDefaultConnection(); | 98 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. |
| 97 CGSSetWindowAlpha(cid, [window windowNumber], alpha); | 99 // CGSConnection cid = _CGSDefaultConnection(); |
| 100 // CGSSetWindowAlpha(cid, [window windowNumber], alpha); |
| 98 } | 101 } |
| 99 | 102 |
| 100 // Scales the window and translates it so that it stays centered relative | 103 // Scales the window and translates it so that it stays centered relative |
| 101 // to its original position. | 104 // to its original position. |
| 102 void SetWindowScale(NSWindow* window, float scale) { | 105 void SetWindowScale(NSWindow* window, float scale) { |
| 103 CGFloat scale_delta = 1.0 - scale; | 106 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. |
| 104 CGFloat cur_scale = 1.0 + scale_delta; | 107 // CGFloat scale_delta = 1.0 - scale; |
| 105 CGAffineTransform transform = | 108 // CGFloat cur_scale = 1.0 + scale_delta; |
| 106 CGAffineTransformMakeScale(cur_scale, cur_scale); | 109 // CGAffineTransform transform = |
| 110 // CGAffineTransformMakeScale(cur_scale, cur_scale); |
| 107 | 111 |
| 108 // Translate the window to keep it centered at the original location. | 112 // // Translate the window to keep it centered at the original location. |
| 109 NSSize window_size = [window frame].size; | 113 // NSSize window_size = [window frame].size; |
| 110 CGFloat scale_offset_x = window_size.width * (1 - cur_scale) / 2.0; | 114 // CGFloat scale_offset_x = window_size.width * (1 - cur_scale) / 2.0; |
| 111 CGFloat scale_offset_y = window_size.height * (1 - cur_scale) / 2.0; | 115 // CGFloat scale_offset_y = window_size.height * (1 - cur_scale) / 2.0; |
| 112 | 116 |
| 113 NSPoint origin = GetCGSWindowScreenOrigin(window); | 117 // NSPoint origin = GetCGSWindowScreenOrigin(window); |
| 114 CGFloat new_x = -origin.x + scale_offset_x; | 118 // CGFloat new_x = -origin.x + scale_offset_x; |
| 115 CGFloat new_y = -origin.y + scale_offset_y; | 119 // CGFloat new_y = -origin.y + scale_offset_y; |
| 116 transform = CGAffineTransformTranslate(transform, new_x, new_y); | 120 // transform = CGAffineTransformTranslate(transform, new_x, new_y); |
| 117 | 121 |
| 118 CGSConnection cid = _CGSDefaultConnection(); | 122 // CGSConnection cid = _CGSDefaultConnection(); |
| 119 CGSSetWindowTransform(cid, [window windowNumber], transform); | 123 // CGSSetWindowTransform(cid, [window windowNumber], transform); |
| 120 } | 124 } |
| 121 | 125 |
| 122 // Unsets any window warp that may have been previously applied. | 126 // Unsets any window warp that may have been previously applied. |
| 123 // Window warp prevents other effects such as CGSSetWindowTransform from | 127 // Window warp prevents other effects such as CGSSetWindowTransform from |
| 124 // being applied. | 128 // being applied. |
| 125 void ClearWindowWarp(NSWindow* window) { | 129 void ClearWindowWarp(NSWindow* window) { |
| 126 CGSConnection cid = _CGSDefaultConnection(); | 130 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. |
| 127 CGSSetWindowWarp(cid, [window windowNumber], 0, 0, NULL); | 131 // CGSConnection cid = _CGSDefaultConnection(); |
| 132 // CGSSetWindowWarp(cid, [window windowNumber], 0, 0, NULL); |
| 128 } | 133 } |
| 129 | 134 |
| 130 // Applies various transformations using a warp effect. The window is | 135 // Applies various transformations using a warp effect. The window is |
| 131 // translated vertically by |y_offset|. The window is scaled by |scale| and | 136 // translated vertically by |y_offset|. The window is scaled by |scale| and |
| 132 // translated so that the it remains centered relative to its original position. | 137 // translated so that the it remains centered relative to its original position. |
| 133 // Finally, perspective is effect is applied by shrinking the top of the window. | 138 // Finally, perspective is effect is applied by shrinking the top of the window. |
| 134 void SetWindowWarp(NSWindow* window, | 139 void SetWindowWarp(NSWindow* window, |
| 135 float y_offset, | 140 float y_offset, |
| 136 float scale, | 141 float scale, |
| 137 float perspective_offset) { | 142 float perspective_offset) { |
| 138 NSRect win_rect = [window frame]; | 143 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. |
| 139 win_rect.origin = NSZeroPoint; | 144 // NSRect win_rect = [window frame]; |
| 140 NSRect screen_rect = win_rect; | 145 // win_rect.origin = NSZeroPoint; |
| 141 screen_rect.origin = GetCGSWindowScreenOrigin(window); | 146 // NSRect screen_rect = win_rect; |
| 147 // screen_rect.origin = GetCGSWindowScreenOrigin(window); |
| 142 | 148 |
| 143 // Apply a vertical translate. | 149 // // Apply a vertical translate. |
| 144 screen_rect.origin.y -= y_offset; | 150 // screen_rect.origin.y -= y_offset; |
| 145 | 151 |
| 146 // Apply a scale and translate to keep the window centered. | 152 // // Apply a scale and translate to keep the window centered. |
| 147 screen_rect.origin.x += (NSWidth(win_rect) - NSWidth(screen_rect)) / 2.0; | 153 // screen_rect.origin.x += (NSWidth(win_rect) - NSWidth(screen_rect)) / 2.0; |
| 148 screen_rect.origin.y += (NSHeight(win_rect) - NSHeight(screen_rect)) / 2.0; | 154 // screen_rect.origin.y += (NSHeight(win_rect) - NSHeight(screen_rect)) / 2.0; |
| 149 | 155 |
| 150 // A 2 x 2 mesh that maps each corner of the window to a location in screen | 156 // // A 2 x 2 mesh that maps each corner of the window to a location in screen |
| 151 // coordinates. Note that the origin of the coordinate system is top, left. | 157 // // coordinates. Note that the origin of the coordinate system is top, left. |
| 152 CGPointWarp mesh[2][2] = { | 158 // CGPointWarp mesh[2][2] = { |
| 153 {{ | 159 // {{ |
| 154 // Top left. | 160 // // Top left. |
| 155 {NSMinX(win_rect), NSMinY(win_rect)}, | 161 // {NSMinX(win_rect), NSMinY(win_rect)}, |
| 156 {NSMinX(screen_rect) + perspective_offset, NSMinY(screen_rect)}, | 162 // {NSMinX(screen_rect) + perspective_offset, NSMinY(screen_rect)}, |
| 157 }, | 163 // }, |
| 158 { | 164 // { |
| 159 // Top right. | 165 // // Top right. |
| 160 {NSMaxX(win_rect), NSMinY(win_rect)}, | 166 // {NSMaxX(win_rect), NSMinY(win_rect)}, |
| 161 {NSMaxX(screen_rect) - perspective_offset, NSMinY(screen_rect)}, }}, | 167 // {NSMaxX(screen_rect) - perspective_offset, NSMinY(screen_rect)}, }}, |
| 162 {{ | 168 // {{ |
| 163 // Bottom left. | 169 // // Bottom left. |
| 164 {NSMinX(win_rect), NSMaxY(win_rect)}, | 170 // {NSMinX(win_rect), NSMaxY(win_rect)}, |
| 165 {NSMinX(screen_rect), NSMaxY(screen_rect)}, | 171 // {NSMinX(screen_rect), NSMaxY(screen_rect)}, |
| 166 }, | 172 // }, |
| 167 { | 173 // { |
| 168 // Bottom right. | 174 // // Bottom right. |
| 169 {NSMaxX(win_rect), NSMaxY(win_rect)}, | 175 // {NSMaxX(win_rect), NSMaxY(win_rect)}, |
| 170 {NSMaxX(screen_rect), NSMaxY(screen_rect)}, }}, | 176 // {NSMaxX(screen_rect), NSMaxY(screen_rect)}, }}, |
| 171 }; | 177 // }; |
| 172 | 178 |
| 173 CGSConnection cid = _CGSDefaultConnection(); | 179 // CGSConnection cid = _CGSDefaultConnection(); |
| 174 CGSSetWindowWarp(cid, [window windowNumber], 2, 2, &(mesh[0][0])); | 180 // CGSSetWindowWarp(cid, [window windowNumber], 2, 2, &(mesh[0][0])); |
| 175 } | 181 } |
| 176 | 182 |
| 177 // Sets the various effects that are a part of the Show/Hide animation. | 183 // Sets the various effects that are a part of the Show/Hide animation. |
| 178 // Value is a number between 0 and 1 where 0 means the window is completely | 184 // Value is a number between 0 and 1 where 0 means the window is completely |
| 179 // hidden and 1 means the window is fully visible. | 185 // hidden and 1 means the window is fully visible. |
| 180 void UpdateWindowShowHideAnimationState(NSWindow* window, CGFloat value) { | 186 void UpdateWindowShowHideAnimationState(NSWindow* window, CGFloat value) { |
| 181 CGFloat inverse_value = 1.0 - value; | 187 CGFloat inverse_value = 1.0 - value; |
| 182 | 188 |
| 183 SetWindowAlpha(window, value); | 189 SetWindowAlpha(window, value); |
| 184 CGFloat y_offset = kShowHideVerticalOffset * inverse_value; | 190 CGFloat y_offset = kShowHideVerticalOffset * inverse_value; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 299 } |
| 294 | 300 |
| 295 SetWindowScale(window_, scale); | 301 SetWindowScale(window_, scale); |
| 296 } | 302 } |
| 297 | 303 |
| 298 - (void)setWindowStateForEnd { | 304 - (void)setWindowStateForEnd { |
| 299 SetWindowScale(window_, 1.0); | 305 SetWindowScale(window_, 1.0); |
| 300 } | 306 } |
| 301 | 307 |
| 302 @end | 308 @end |
| OLD | NEW |