Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/base/cocoa/constrained_window/constrained_window_animation.mm

Issue 1853373002: Revert of Temporarily disable all calls of CGS private APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 83 // Origin is relative to the screen with the menu bar (the screen at index 0).
84 // 0). 84 // Note, this is not the same as mainScreen which is the screen with the key
85 // // Note, this is not the same as mainScreen which is the screen with the 85 // window.
86 // key 86 NSScreen* main_screen = [screens objectAtIndex:0];
87 // // window. 87
88 // NSScreen* main_screen = [screens objectAtIndex:0]; 88 NSRect window_frame = [window frame];
89 // 89 NSRect screen_frame = [main_screen frame];
90 // NSRect window_frame = [window frame]; 90 return NSMakePoint(NSMinX(window_frame),
91 // NSRect screen_frame = [main_screen frame]; 91 NSHeight(screen_frame) - NSMaxY(window_frame));
92 // return NSMakePoint(NSMinX(window_frame), 92 }
93 // NSHeight(screen_frame) - NSMaxY(window_frame));
94 // }
95 93
96 // Set the transparency of the window. 94 // Set the transparency of the window.
97 void SetWindowAlpha(NSWindow* window, float alpha) { 95 void SetWindowAlpha(NSWindow* window, float alpha) {
98 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. 96 CGSConnection cid = _CGSDefaultConnection();
99 // CGSConnection cid = _CGSDefaultConnection(); 97 CGSSetWindowAlpha(cid, [window windowNumber], alpha);
100 // CGSSetWindowAlpha(cid, [window windowNumber], alpha);
101 } 98 }
102 99
103 // Scales the window and translates it so that it stays centered relative 100 // Scales the window and translates it so that it stays centered relative
104 // to its original position. 101 // to its original position.
105 void SetWindowScale(NSWindow* window, float scale) { 102 void SetWindowScale(NSWindow* window, float scale) {
106 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. 103 CGFloat scale_delta = 1.0 - scale;
107 // CGFloat scale_delta = 1.0 - scale; 104 CGFloat cur_scale = 1.0 + scale_delta;
108 // CGFloat cur_scale = 1.0 + scale_delta; 105 CGAffineTransform transform =
109 // CGAffineTransform transform = 106 CGAffineTransformMakeScale(cur_scale, cur_scale);
110 // CGAffineTransformMakeScale(cur_scale, cur_scale);
111 107
112 // // Translate the window to keep it centered at the original location. 108 // Translate the window to keep it centered at the original location.
113 // NSSize window_size = [window frame].size; 109 NSSize window_size = [window frame].size;
114 // CGFloat scale_offset_x = window_size.width * (1 - cur_scale) / 2.0; 110 CGFloat scale_offset_x = window_size.width * (1 - cur_scale) / 2.0;
115 // CGFloat scale_offset_y = window_size.height * (1 - cur_scale) / 2.0; 111 CGFloat scale_offset_y = window_size.height * (1 - cur_scale) / 2.0;
116 112
117 // NSPoint origin = GetCGSWindowScreenOrigin(window); 113 NSPoint origin = GetCGSWindowScreenOrigin(window);
118 // CGFloat new_x = -origin.x + scale_offset_x; 114 CGFloat new_x = -origin.x + scale_offset_x;
119 // CGFloat new_y = -origin.y + scale_offset_y; 115 CGFloat new_y = -origin.y + scale_offset_y;
120 // transform = CGAffineTransformTranslate(transform, new_x, new_y); 116 transform = CGAffineTransformTranslate(transform, new_x, new_y);
121 117
122 // CGSConnection cid = _CGSDefaultConnection(); 118 CGSConnection cid = _CGSDefaultConnection();
123 // CGSSetWindowTransform(cid, [window windowNumber], transform); 119 CGSSetWindowTransform(cid, [window windowNumber], transform);
124 } 120 }
125 121
126 // Unsets any window warp that may have been previously applied. 122 // Unsets any window warp that may have been previously applied.
127 // Window warp prevents other effects such as CGSSetWindowTransform from 123 // Window warp prevents other effects such as CGSSetWindowTransform from
128 // being applied. 124 // being applied.
129 void ClearWindowWarp(NSWindow* window) { 125 void ClearWindowWarp(NSWindow* window) {
130 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. 126 CGSConnection cid = _CGSDefaultConnection();
131 // CGSConnection cid = _CGSDefaultConnection(); 127 CGSSetWindowWarp(cid, [window windowNumber], 0, 0, NULL);
132 // CGSSetWindowWarp(cid, [window windowNumber], 0, 0, NULL);
133 } 128 }
134 129
135 // Applies various transformations using a warp effect. The window is 130 // Applies various transformations using a warp effect. The window is
136 // translated vertically by |y_offset|. The window is scaled by |scale| and 131 // translated vertically by |y_offset|. The window is scaled by |scale| and
137 // translated so that the it remains centered relative to its original position. 132 // translated so that the it remains centered relative to its original position.
138 // Finally, perspective is effect is applied by shrinking the top of the window. 133 // Finally, perspective is effect is applied by shrinking the top of the window.
139 void SetWindowWarp(NSWindow* window, 134 void SetWindowWarp(NSWindow* window,
140 float y_offset, 135 float y_offset,
141 float scale, 136 float scale,
142 float perspective_offset) { 137 float perspective_offset) {
143 // TODO(erikchen): Temporarily disabled. https://crbug.com/515627. 138 NSRect win_rect = [window frame];
144 // NSRect win_rect = [window frame]; 139 win_rect.origin = NSZeroPoint;
145 // win_rect.origin = NSZeroPoint; 140 NSRect screen_rect = win_rect;
146 // NSRect screen_rect = win_rect; 141 screen_rect.origin = GetCGSWindowScreenOrigin(window);
147 // screen_rect.origin = GetCGSWindowScreenOrigin(window);
148 142
149 // // Apply a vertical translate. 143 // Apply a vertical translate.
150 // screen_rect.origin.y -= y_offset; 144 screen_rect.origin.y -= y_offset;
151 145
152 // // Apply a scale and translate to keep the window centered. 146 // Apply a scale and translate to keep the window centered.
153 // screen_rect.origin.x += (NSWidth(win_rect) - NSWidth(screen_rect)) / 2.0; 147 screen_rect.origin.x += (NSWidth(win_rect) - NSWidth(screen_rect)) / 2.0;
154 // screen_rect.origin.y += (NSHeight(win_rect) - NSHeight(screen_rect)) / 2.0; 148 screen_rect.origin.y += (NSHeight(win_rect) - NSHeight(screen_rect)) / 2.0;
155 149
156 // // A 2 x 2 mesh that maps each corner of the window to a location in screen 150 // A 2 x 2 mesh that maps each corner of the window to a location in screen
157 // // coordinates. Note that the origin of the coordinate system is top, left. 151 // coordinates. Note that the origin of the coordinate system is top, left.
158 // CGPointWarp mesh[2][2] = { 152 CGPointWarp mesh[2][2] = {
159 // {{ 153 {{
160 // // Top left. 154 // Top left.
161 // {NSMinX(win_rect), NSMinY(win_rect)}, 155 {NSMinX(win_rect), NSMinY(win_rect)},
162 // {NSMinX(screen_rect) + perspective_offset, NSMinY(screen_rect)}, 156 {NSMinX(screen_rect) + perspective_offset, NSMinY(screen_rect)},
163 // }, 157 },
164 // { 158 {
165 // // Top right. 159 // Top right.
166 // {NSMaxX(win_rect), NSMinY(win_rect)}, 160 {NSMaxX(win_rect), NSMinY(win_rect)},
167 // {NSMaxX(screen_rect) - perspective_offset, NSMinY(screen_rect)}, }}, 161 {NSMaxX(screen_rect) - perspective_offset, NSMinY(screen_rect)}, }},
168 // {{ 162 {{
169 // // Bottom left. 163 // Bottom left.
170 // {NSMinX(win_rect), NSMaxY(win_rect)}, 164 {NSMinX(win_rect), NSMaxY(win_rect)},
171 // {NSMinX(screen_rect), NSMaxY(screen_rect)}, 165 {NSMinX(screen_rect), NSMaxY(screen_rect)},
172 // }, 166 },
173 // { 167 {
174 // // Bottom right. 168 // Bottom right.
175 // {NSMaxX(win_rect), NSMaxY(win_rect)}, 169 {NSMaxX(win_rect), NSMaxY(win_rect)},
176 // {NSMaxX(screen_rect), NSMaxY(screen_rect)}, }}, 170 {NSMaxX(screen_rect), NSMaxY(screen_rect)}, }},
177 // }; 171 };
178 172
179 // CGSConnection cid = _CGSDefaultConnection(); 173 CGSConnection cid = _CGSDefaultConnection();
180 // CGSSetWindowWarp(cid, [window windowNumber], 2, 2, &(mesh[0][0])); 174 CGSSetWindowWarp(cid, [window windowNumber], 2, 2, &(mesh[0][0]));
181 } 175 }
182 176
183 // Sets the various effects that are a part of the Show/Hide animation. 177 // Sets the various effects that are a part of the Show/Hide animation.
184 // Value is a number between 0 and 1 where 0 means the window is completely 178 // Value is a number between 0 and 1 where 0 means the window is completely
185 // hidden and 1 means the window is fully visible. 179 // hidden and 1 means the window is fully visible.
186 void UpdateWindowShowHideAnimationState(NSWindow* window, CGFloat value) { 180 void UpdateWindowShowHideAnimationState(NSWindow* window, CGFloat value) {
187 CGFloat inverse_value = 1.0 - value; 181 CGFloat inverse_value = 1.0 - value;
188 182
189 SetWindowAlpha(window, value); 183 SetWindowAlpha(window, value);
190 CGFloat y_offset = kShowHideVerticalOffset * inverse_value; 184 CGFloat y_offset = kShowHideVerticalOffset * inverse_value;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 293 }
300 294
301 SetWindowScale(window_, scale); 295 SetWindowScale(window_, scale);
302 } 296 }
303 297
304 - (void)setWindowStateForEnd { 298 - (void)setWindowStateForEnd {
305 SetWindowScale(window_, 1.0); 299 SetWindowScale(window_, 1.0);
306 } 300 }
307 301
308 @end 302 @end
OLDNEW
« no previous file with comments | « no previous file | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698