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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_layout.mm

Issue 2313723004: cocoa: flip window controls and profile switcher for RTL (Closed)
Patch Set: Created 4 years, 3 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 | chrome/browser/ui/cocoa/framed_browser_window.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_layout.h" 5 #import "chrome/browser/ui/cocoa/browser_window_layout.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
13 14
14 namespace chrome { 15 namespace chrome {
15 16
16 // The height of the tab strip. 17 // The height of the tab strip.
17 const CGFloat kTabStripHeight = 37; 18 const CGFloat kTabStripHeight = 37;
18 19
19 } // namespace chrome 20 } // namespace chrome
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 0, maxY_ - chrome::kTabStripHeight, width, chrome::kTabStripHeight); 191 0, maxY_ - chrome::kTabStripHeight, width, chrome::kTabStripHeight);
191 maxY_ = NSMinY(layout.frame); 192 maxY_ = NSMinY(layout.frame);
192 193
193 // In Yosemite, there is no longer an exit fullscreen button in the top-right 194 // In Yosemite, there is no longer an exit fullscreen button in the top-right
194 // corner of the OSX Menu Bar. Instead, a Cocoa application's toolbar is 195 // corner of the OSX Menu Bar. Instead, a Cocoa application's toolbar is
195 // expected to have traffic lights. Chrome doesn't use an NSToolbar, so it 196 // expected to have traffic lights. Chrome doesn't use an NSToolbar, so it
196 // needs to manually add the traffic lights to the tab strip. 197 // needs to manually add the traffic lights to the tab strip.
197 layout.addCustomWindowControls = 198 layout.addCustomWindowControls =
198 parameters_.inAnyFullscreen && parameters_.isOSYosemiteOrLater; 199 parameters_.inAnyFullscreen && parameters_.isOSYosemiteOrLater;
199 200
200 // Set left indentation based on fullscreen mode status.
201 if (!parameters_.inAnyFullscreen || layout.addCustomWindowControls)
202 layout.leftIndent = [TabStripController defaultLeftIndentForControls];
203
204 // Lay out the icognito/avatar badge because calculating the indentation on 201 // Lay out the icognito/avatar badge because calculating the indentation on
205 // the right depends on it. 202 // the right depends on it.
206 if (parameters_.shouldShowAvatar) { 203 if (parameters_.shouldShowAvatar) {
207 CGFloat badgeXOffset = -kAvatarRightOffset; 204 CGFloat badgeXOffset = -kAvatarRightOffset;
208 CGFloat badgeYOffset = 0; 205 CGFloat badgeYOffset = 0;
209 CGFloat buttonHeight = parameters_.avatarSize.height; 206 CGFloat buttonHeight = parameters_.avatarSize.height;
210 207
211 if (parameters_.shouldUseNewAvatar) { 208 if (parameters_.shouldUseNewAvatar) {
212 // The fullscreen icon (if present) is displayed to the right of the 209 // The fullscreen icon (if present) is displayed to the right of the
213 // new style profile button. 210 // new style profile button.
214 if (!NSIsEmptyRect(parameters_.fullscreenButtonFrame)) 211 if (!NSIsEmptyRect(parameters_.fullscreenButtonFrame))
215 badgeXOffset = -kLocationBarRightOffset; 212 badgeXOffset = -kLocationBarRightOffset;
216 213
217 // Center the button, but make sure that it's pixel aligned on non-retina 214 // Center the button, but make sure that it's pixel aligned on non-retina
218 // displays. Use trunc() instead of round() to mimic the behavior of 215 // displays. Use trunc() instead of round() to mimic the behavior of
219 // autoresizesSubviews. 216 // autoresizesSubviews.
220 badgeYOffset = trunc((chrome::kTabStripHeight - buttonHeight) / 2); 217 badgeYOffset = trunc((chrome::kTabStripHeight - buttonHeight) / 2);
221 } else { 218 } else {
222 // Actually place the badge *above* |maxY|, by +2 to miss the divider. 219 // Actually place the badge *above* |maxY|, by +2 to miss the divider.
223 badgeYOffset = 2 * parameters_.avatarLineWidth; 220 badgeYOffset = 2 * parameters_.avatarLineWidth;
224 } 221 }
225 222
226 NSSize size = NSMakeSize(parameters_.avatarSize.width, 223 NSSize size = NSMakeSize(parameters_.avatarSize.width,
227 std::min(buttonHeight, chrome::kTabStripHeight)); 224 std::min(buttonHeight, chrome::kTabStripHeight));
228 NSPoint origin = 225 NSPoint origin;
229 NSMakePoint(width - parameters_.avatarSize.width + badgeXOffset, 226 if (base::i18n::IsRTL()) {
230 maxY_ + badgeYOffset); 227 origin = NSMakePoint(-badgeXOffset, maxY_ + badgeYOffset);
228 } else {
229 origin = NSMakePoint(width - parameters_.avatarSize.width + badgeXOffset,
230 maxY_ + badgeYOffset);
231 }
231 layout.avatarFrame = 232 layout.avatarFrame =
232 NSMakeRect(origin.x, origin.y, size.width, size.height); 233 NSMakeRect(origin.x, origin.y, size.width, size.height);
233 } 234 }
234 235
236 // Set left indentation based on fullscreen mode status.
237 if (!parameters_.inAnyFullscreen || layout.addCustomWindowControls) {
238 if (base::i18n::IsRTL())
239 layout.leftIndent = NSMaxX(layout.avatarFrame);
240 else
241 layout.leftIndent = [TabStripController defaultLeftIndentForControls];
242 }
243
235 // Calculate the right indentation. 244 // Calculate the right indentation.
236 // On 10.7 Lion to 10.9 Mavericks, there will be a fullscreen button when not 245 // On 10.7 Lion to 10.9 Mavericks, there will be a fullscreen button when not
237 // in fullscreen mode. 246 // in fullscreen mode.
238 // There may also be a profile button, which can be on the right of the 247 // There may also be a profile button, which can be on the right of the
239 // fullscreen button (old style), or to its left (new style). 248 // fullscreen button (old style), or to its left (new style).
240 // The right indentation is calculated to prevent the tab strip from 249 // The right indentation is calculated to prevent the tab strip from
241 // overlapping these buttons. 250 // overlapping these buttons.
242 CGFloat maxX = width; 251 if (base::i18n::IsRTL()) {
243 if (!NSIsEmptyRect(parameters_.fullscreenButtonFrame)) { 252 layout.rightIndent = [TabStripController defaultLeftIndentForControls];
244 maxX = NSMinX(parameters_.fullscreenButtonFrame); 253 } else {
254 CGFloat maxX = width;
255 if (!NSIsEmptyRect(parameters_.fullscreenButtonFrame)) {
256 maxX = NSMinX(parameters_.fullscreenButtonFrame);
257 }
258 if (parameters_.shouldShowAvatar) {
259 maxX = std::min(maxX, NSMinX(layout.avatarFrame));
260 }
261 layout.rightIndent = width - maxX;
Avi (use Gerrit) 2016/09/06 15:38:00 Some thoughts. I would have thought that the code
245 } 262 }
246 if (parameters_.shouldShowAvatar) {
247 maxX = std::min(maxX, NSMinX(layout.avatarFrame));
248 }
249 layout.rightIndent = width - maxX;
250 263
251 output_.tabStripLayout = layout; 264 output_.tabStripLayout = layout;
252 } 265 }
253 266
254 - (void)computeContentViewLayout { 267 - (void)computeContentViewLayout {
255 chrome::LayoutParameters parameters = parameters_; 268 chrome::LayoutParameters parameters = parameters_;
256 CGFloat maxY = maxY_; 269 CGFloat maxY = maxY_;
257 270
258 // Sanity-check |maxY|. 271 // Sanity-check |maxY|.
259 DCHECK_GE(maxY, 0); 272 DCHECK_GE(maxY, 0);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 399
387 @end 400 @end
388 401
389 @implementation BrowserWindowLayout (ExposedForTesting) 402 @implementation BrowserWindowLayout (ExposedForTesting)
390 403
391 - (void)setOSYosemiteOrLater:(BOOL)osYosemiteOrLater { 404 - (void)setOSYosemiteOrLater:(BOOL)osYosemiteOrLater {
392 parameters_.isOSYosemiteOrLater = osYosemiteOrLater; 405 parameters_.isOSYosemiteOrLater = osYosemiteOrLater;
393 } 406 }
394 407
395 @end 408 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/framed_browser_window.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698