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/toolbar/toolbar_controller.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "chrome/browser/ui/browser_commands.h" | 29 #include "chrome/browser/ui/browser_commands.h" |
30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h" | 31 #import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h" |
32 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 32 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
33 #include "chrome/browser/ui/cocoa/drag_util.h" | 33 #include "chrome/browser/ui/cocoa/drag_util.h" |
34 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 34 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
35 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 35 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
36 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 36 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
37 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" | 37 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" |
38 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 38 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
39 #import "chrome/browser/ui/cocoa/l10n_util.h" | |
39 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
40 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
42 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
43 #import "chrome/browser/ui/cocoa/menu_button.h" | 44 #import "chrome/browser/ui/cocoa/menu_button.h" |
44 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h" | 45 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h" |
45 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_cell.h" | 46 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_cell.h" |
46 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" | 47 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" |
47 #import "chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.h" | 48 #import "chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.h" |
48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h" | 49 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; | 139 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; |
139 } | 140 } |
140 | 141 |
141 } // namespace | 142 } // namespace |
142 | 143 |
143 @interface ToolbarController() | 144 @interface ToolbarController() |
144 @property(assign, nonatomic) Browser* browser; | 145 @property(assign, nonatomic) Browser* browser; |
145 // Height of the location bar. Used for animating the toolbar in and out when | 146 // Height of the location bar. Used for animating the toolbar in and out when |
146 // the location bar is displayed stand-alone for bookmark apps. | 147 // the location bar is displayed stand-alone for bookmark apps. |
147 + (CGFloat)locationBarHeight; | 148 + (CGFloat)locationBarHeight; |
148 // Return the amount of left padding that the app menu should have. | 149 // Return the amount of horizontal padding that the app menu should have on |
149 + (CGFloat)appMenuLeftPadding; | 150 // each side. |
151 + (CGFloat)appMenuPadding; | |
150 - (void)cleanUp; | 152 - (void)cleanUp; |
151 - (void)addAccessibilityDescriptions; | 153 - (void)addAccessibilityDescriptions; |
152 - (void)initCommandStatus:(CommandUpdater*)commands; | 154 - (void)initCommandStatus:(CommandUpdater*)commands; |
153 - (void)prefChanged:(const std::string&)prefName; | 155 - (void)prefChanged:(const std::string&)prefName; |
154 - (ToolbarView*)toolbarView; | 156 - (ToolbarView*)toolbarView; |
155 // Height of the toolbar in pixels when the bookmark bar is closed. | 157 // Height of the toolbar in pixels when the bookmark bar is closed. |
156 - (CGFloat)baseToolbarHeight; | 158 - (CGFloat)baseToolbarHeight; |
157 - (void)toolbarFrameChanged; | 159 - (void)toolbarFrameChanged; |
158 - (void)showLocationBarOnly; | 160 - (void)showLocationBarOnly; |
159 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; | 161 - (void)pinLocationBarBeforeBrowserActionsContainerAndAnimate:(BOOL)animate; |
160 - (void)maintainMinimumLocationBarWidth; | 162 - (void)maintainMinimumLocationBarWidth; |
161 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 163 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
162 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 164 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
163 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 165 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
164 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; | 166 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; |
165 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 167 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
166 - (void)updateAppMenuButtonSeverity:(AppMenuIconController::Severity)severity | 168 - (void)updateAppMenuButtonSeverity:(AppMenuIconController::Severity)severity |
167 iconType:(AppMenuIconController::IconType)iconType | 169 iconType:(AppMenuIconController::IconType)iconType |
168 animate:(BOOL)animate; | 170 animate:(BOOL)animate; |
169 @end | 171 @end |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 } // namespace ToolbarControllerInternal | 231 } // namespace ToolbarControllerInternal |
230 | 232 |
231 @implementation ToolbarController | 233 @implementation ToolbarController |
232 | 234 |
233 @synthesize browser = browser_; | 235 @synthesize browser = browser_; |
234 | 236 |
235 + (CGFloat)locationBarHeight { | 237 + (CGFloat)locationBarHeight { |
236 return kLocationBarHeight; | 238 return kLocationBarHeight; |
237 } | 239 } |
238 | 240 |
239 + (CGFloat)appMenuLeftPadding { | 241 + (CGFloat)appMenuPadding { |
240 return kElementPadding; | 242 return kElementPadding; |
241 } | 243 } |
242 | 244 |
243 + (CGFloat)materialDesignButtonInset { | 245 + (CGFloat)materialDesignButtonInset { |
244 return kButtonInset; | 246 return kButtonInset; |
245 } | 247 } |
246 | 248 |
247 - (id)initWithCommands:(CommandUpdater*)commands | 249 - (id)initWithCommands:(CommandUpdater*)commands |
248 profile:(Profile*)profile | 250 profile:(Profile*)profile |
249 browser:(Browser*)browser | 251 browser:(Browser*)browser |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 } | 292 } |
291 | 293 |
292 - (void)viewDidLoad { | 294 - (void)viewDidLoad { |
293 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may | 295 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may |
294 // be called, don't initialize twice. | 296 // be called, don't initialize twice. |
295 if (locationBarView_) { | 297 if (locationBarView_) { |
296 DCHECK(base::mac::IsAtLeastOS10_10()); | 298 DCHECK(base::mac::IsAtLeastOS10_10()); |
297 return; | 299 return; |
298 } | 300 } |
299 | 301 |
302 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | |
303 NSAutoresizingMaskOptions leadingButtonMask = | |
304 isRTL ? NSViewMinXMargin | NSViewMinYMargin | |
305 : NSViewMaxXMargin | NSViewMinYMargin; | |
306 NSAutoresizingMaskOptions trailingButtonMask = | |
307 isRTL ? NSViewMaxXMargin | NSViewMinYMargin | |
308 : NSViewMinXMargin | NSViewMinYMargin; | |
309 | |
300 // Make Material Design layout adjustments to the NIB items. | 310 // Make Material Design layout adjustments to the NIB items. |
301 ToolbarView* toolbarView = [self toolbarView]; | 311 ToolbarView* toolbarView = [self toolbarView]; |
302 NSRect toolbarBounds = [toolbarView bounds]; | 312 NSRect toolbarBounds = [toolbarView bounds]; |
303 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; | 313 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; |
304 | 314 |
305 // Set the toolbar height. | 315 // Set the toolbar height. |
306 NSRect frame = [toolbarView frame]; | 316 NSRect frame = [toolbarView frame]; |
307 frame.size.height = [self baseToolbarHeight]; | 317 frame.size.height = [self baseToolbarHeight]; |
308 [toolbarView setFrame:frame]; | 318 [toolbarView setFrame:frame]; |
309 | 319 |
310 NSRect backButtonFrame = [backButton_ frame]; | 320 NSArray* leadingButtons = |
311 backButtonFrame.origin.x = kElementPadding + kButtonInset; | 321 @[ backButton_, forwardButton_, reloadButton_, homeButton_ ]; |
312 backButtonFrame.origin.y = | 322 const CGFloat xStart = kElementPadding + kButtonInset; |
323 const CGFloat xOffset = toolbarButtonSize.width + kButtonInset * 2; | |
324 const CGFloat yPosition = | |
313 NSMaxY(toolbarBounds) - kElementPadding - toolbarButtonSize.height; | 325 NSMaxY(toolbarBounds) - kElementPadding - toolbarButtonSize.height; |
314 backButtonFrame.size = toolbarButtonSize; | 326 for (NSUInteger i = 0; i < [leadingButtons count]; i++) { |
315 [backButton_ setFrame:backButtonFrame]; | 327 NSButton* button = leadingButtons[i]; |
316 | 328 NSRect buttonFrame = [button frame]; |
317 NSRect forwardButtonFrame = [forwardButton_ frame]; | 329 buttonFrame.size = toolbarButtonSize; |
318 forwardButtonFrame.origin.x = NSMaxX(backButtonFrame) + 2 * kButtonInset; | 330 buttonFrame.origin.y = yPosition; |
319 forwardButtonFrame.origin.y = backButtonFrame.origin.y; | 331 const CGFloat xPosition = xStart + i * xOffset; |
320 forwardButtonFrame.size = toolbarButtonSize; | 332 buttonFrame.origin.x = |
321 [forwardButton_ setFrame:forwardButtonFrame]; | 333 isRTL ? NSWidth(frame) - toolbarButtonSize.width - xPosition |
322 | 334 : xPosition; |
323 NSRect reloadButtonFrame = [reloadButton_ frame]; | 335 [button setFrame:buttonFrame]; |
324 reloadButtonFrame.origin.x = NSMaxX(forwardButtonFrame) + 2 * kButtonInset; | 336 [button setAutoresizingMask:leadingButtonMask]; |
325 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; | 337 } |
326 reloadButtonFrame.size = toolbarButtonSize; | |
327 [reloadButton_ setFrame:reloadButtonFrame]; | |
328 | |
329 NSRect homeButtonFrame = [homeButton_ frame]; | |
330 homeButtonFrame.origin.x = NSMaxX(reloadButtonFrame) + 2 * kButtonInset; | |
331 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; | |
332 homeButtonFrame.size = toolbarButtonSize; | |
333 [homeButton_ setFrame:homeButtonFrame]; | |
334 | 338 |
335 // Replace the app button from the nib with an AppToolbarButton instance for | 339 // Replace the app button from the nib with an AppToolbarButton instance for |
336 // Material Design. | 340 // Material Design. |
337 AppToolbarButton* newMenuButton = | 341 AppToolbarButton* newMenuButton = |
338 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] | 342 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
339 autorelease]; | 343 autorelease]; |
340 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; | 344 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
341 [[appMenuButton_ superview] addSubview:newMenuButton]; | 345 [[appMenuButton_ superview] addSubview:newMenuButton]; |
342 [appMenuButton_ removeFromSuperview]; | 346 [appMenuButton_ removeFromSuperview]; |
343 appMenuButton_ = newMenuButton; | 347 appMenuButton_ = newMenuButton; |
344 | 348 |
345 // Adjust the menu button's position. | 349 // Adjust the menu button's position. |
346 NSRect menuButtonFrame = [appMenuButton_ frame]; | 350 NSRect menuButtonFrame = [appMenuButton_ frame]; |
347 CGFloat menuButtonFrameMaxX = | 351 if (isRTL) { |
348 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; | 352 menuButtonFrame.origin.x = [ToolbarController appMenuPadding]; |
349 menuButtonFrame.origin.x = | 353 } else { |
350 menuButtonFrameMaxX - kButtonInset - toolbarButtonSize.width; | 354 CGFloat menuButtonFrameMaxX = |
351 menuButtonFrame.origin.y = homeButtonFrame.origin.y; | 355 NSMaxX(toolbarBounds) - [ToolbarController appMenuPadding]; |
356 menuButtonFrame.origin.x = | |
357 menuButtonFrameMaxX - kButtonInset - toolbarButtonSize.width; | |
358 } | |
359 menuButtonFrame.origin.y = yPosition; | |
352 menuButtonFrame.size = toolbarButtonSize; | 360 menuButtonFrame.size = toolbarButtonSize; |
353 [appMenuButton_ setFrame:menuButtonFrame]; | 361 [appMenuButton_ setFrame:menuButtonFrame]; |
362 [appMenuButton_ setAutoresizingMask:trailingButtonMask]; | |
354 | 363 |
355 // Adjust the size and location on the location bar to take up the | 364 // Adjust the size and location on the location bar to take up the |
356 // space between the reload and menu buttons. | 365 // space between the reload and menu buttons. |
357 NSRect locationBarFrame = [locationBar_ frame]; | 366 NSRect locationBarFrame = [locationBar_ frame]; |
358 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + kButtonInset; | 367 locationBarFrame.origin.x = isRTL |
359 if (![homeButton_ isHidden]) { | 368 ? NSMaxX(menuButtonFrame) + kButtonInset |
360 // Ensure proper spacing between the home button and the location bar. | 369 : NSMaxX([homeButton_ frame]) + kButtonInset; |
370 if (![homeButton_ isHidden] && !isRTL) { | |
371 // Ensure proper spacing between the home button and location bar | |
361 locationBarFrame.origin.x += kElementPadding; | 372 locationBarFrame.origin.x += kElementPadding; |
362 } | 373 } |
363 locationBarFrame.origin.y = | 374 locationBarFrame.origin.y = |
364 NSMaxY(toolbarBounds) - kLocationBarPadding - kLocationBarHeight; | 375 NSMaxY(toolbarBounds) - kLocationBarPadding - kLocationBarHeight; |
365 locationBarFrame.size.width = | 376 CGFloat rightEdge = 0; |
366 menuButtonFrame.origin.x - | 377 if (isRTL) { |
367 locationBarFrame.origin.x; | 378 rightEdge = NSMinX([homeButton_ frame]) - kButtonInset; |
379 if (![homeButton_ isHidden]) | |
380 rightEdge -= kElementPadding; | |
381 } else { | |
382 rightEdge = NSMinX(menuButtonFrame); | |
383 } | |
384 locationBarFrame.size.width = rightEdge - NSMinX(locationBarFrame); | |
385 | |
368 locationBarFrame.size.height = kLocationBarHeight; | 386 locationBarFrame.size.height = kLocationBarHeight; |
369 [locationBar_ setFrame:locationBarFrame]; | 387 [locationBar_ setFrame:locationBarFrame]; |
370 | 388 |
371 // Correctly position the extension buttons' container view. | 389 // Correctly position the extension buttons' container view. |
372 NSRect containerFrame = [browserActionsContainerView_ frame]; | 390 NSRect containerFrame = [browserActionsContainerView_ frame]; |
373 containerFrame.size.width += kButtonInset; | 391 containerFrame.size.width += kButtonInset; |
374 containerFrame.origin.y = locationBarFrame.origin.y + kContainerYOffset; | 392 containerFrame.origin.y = locationBarFrame.origin.y + kContainerYOffset; |
375 containerFrame.size.height = toolbarButtonSize.height; | 393 containerFrame.size.height = toolbarButtonSize.height; |
394 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | |
395 containerFrame.origin.x = NSMinX(locationBarFrame); | |
376 [browserActionsContainerView_ setFrame:containerFrame]; | 396 [browserActionsContainerView_ setFrame:containerFrame]; |
397 [browserActionsContainerView_ setAutoresizingMask:trailingButtonMask]; | |
377 | 398 |
378 notificationBridge_.reset( | 399 notificationBridge_.reset( |
379 new ToolbarControllerInternal::NotificationBridge(self)); | 400 new ToolbarControllerInternal::NotificationBridge(self)); |
380 notificationBridge_->UpdateSeverity(); | 401 notificationBridge_->UpdateSeverity(); |
381 | 402 |
382 [appMenuButton_ setOpenMenuOnClick:YES]; | 403 [appMenuButton_ setOpenMenuOnClick:YES]; |
383 | 404 |
384 [backButton_ setOpenMenuOnRightClick:YES]; | 405 [backButton_ setOpenMenuOnRightClick:YES]; |
385 [forwardButton_ setOpenMenuOnRightClick:YES]; | 406 [forwardButton_ setOpenMenuOnRightClick:YES]; |
386 | 407 |
(...skipping 26 matching lines...) Expand all Loading... | |
413 // and then add them to the toolbar based on those prefs. | 434 // and then add them to the toolbar based on those prefs. |
414 PrefService* prefs = profile_->GetPrefs(); | 435 PrefService* prefs = profile_->GetPrefs(); |
415 showHomeButton_.Init( | 436 showHomeButton_.Init( |
416 prefs::kShowHomeButton, prefs, | 437 prefs::kShowHomeButton, prefs, |
417 base::Bind( | 438 base::Bind( |
418 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, | 439 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, |
419 base::Unretained(notificationBridge_.get()))); | 440 base::Unretained(notificationBridge_.get()))); |
420 [self showOptionalHomeButton]; | 441 [self showOptionalHomeButton]; |
421 [self installAppMenu]; | 442 [self installAppMenu]; |
422 | 443 |
423 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 444 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; |
424 | 445 |
425 // Create the controllers for the back/forward menus. | 446 // Create the controllers for the back/forward menus. |
426 backMenuController_.reset([[BackForwardMenuController alloc] | 447 backMenuController_.reset([[BackForwardMenuController alloc] |
427 initWithBrowser:browser_ | 448 initWithBrowser:browser_ |
428 modelType:BACK_FORWARD_MENU_TYPE_BACK | 449 modelType:BACK_FORWARD_MENU_TYPE_BACK |
429 button:backButton_]); | 450 button:backButton_]); |
430 forwardMenuController_.reset([[BackForwardMenuController alloc] | 451 forwardMenuController_.reset([[BackForwardMenuController alloc] |
431 initWithBrowser:browser_ | 452 initWithBrowser:browser_ |
432 modelType:BACK_FORWARD_MENU_TYPE_FORWARD | 453 modelType:BACK_FORWARD_MENU_TYPE_FORWARD |
433 button:forwardButton_]); | 454 button:forwardButton_]); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 [self showLocationBarOnly]; | 702 [self showLocationBarOnly]; |
682 } | 703 } |
683 | 704 |
684 // (Private) Returns the backdrop to the toolbar as a ToolbarView. | 705 // (Private) Returns the backdrop to the toolbar as a ToolbarView. |
685 - (ToolbarView*)toolbarView{ | 706 - (ToolbarView*)toolbarView{ |
686 return base::mac::ObjCCastStrict<ToolbarView>([self view]); | 707 return base::mac::ObjCCastStrict<ToolbarView>([self view]); |
687 } | 708 } |
688 | 709 |
689 - (id)customFieldEditorForObject:(id)obj { | 710 - (id)customFieldEditorForObject:(id)obj { |
690 if (obj == locationBar_) { | 711 if (obj == locationBar_) { |
691 // Lazilly construct Field editor, Cocoa UI code always runs on the | 712 // Lazily construct Field editor, Cocoa UI code always runs on the |
692 // same thread, so there shoudn't be a race condition here. | 713 // same thread, so there shoudn't be a race condition here. |
693 if (autocompleteTextFieldEditor_.get() == nil) { | 714 if (autocompleteTextFieldEditor_.get() == nil) { |
694 autocompleteTextFieldEditor_.reset( | 715 autocompleteTextFieldEditor_.reset( |
695 [[AutocompleteTextFieldEditor alloc] init]); | 716 [[AutocompleteTextFieldEditor alloc] init]); |
696 } | 717 } |
697 | 718 |
698 // This needs to be called every time, otherwise notifications | 719 // This needs to be called every time, otherwise notifications |
699 // aren't sent correctly. | 720 // aren't sent correctly. |
700 DCHECK(autocompleteTextFieldEditor_.get()); | 721 DCHECK(autocompleteTextFieldEditor_.get()); |
701 [autocompleteTextFieldEditor_.get() setFieldEditor:YES]; | 722 [autocompleteTextFieldEditor_.get() setFieldEditor:YES]; |
702 return autocompleteTextFieldEditor_.get(); | 723 return autocompleteTextFieldEditor_.get(); |
703 } | 724 } |
704 return nil; | 725 return nil; |
705 } | 726 } |
706 | 727 |
707 // Returns an array of views in the order of the outlets above. | 728 // Returns an array of views, ordered leading to trailing. |
708 - (NSArray*)toolbarViews { | 729 - (NSArray*)toolbarViews { |
709 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, | 730 return @[ |
710 homeButton_, appMenuButton_, locationBar_, | 731 backButton_, forwardButton_, reloadButton_, homeButton_, locationBar_, |
711 browserActionsContainerView_, nil]; | 732 browserActionsContainerView_, appMenuButton_ |
712 } | 733 ]; |
713 | |
714 // Moves |rect| to the right by |delta|, keeping the right side fixed by | |
715 // shrinking the width to compensate. Passing a negative value for |deltaX| | |
716 // moves to the left and increases the width. | |
717 - (NSRect)adjustRect:(NSRect)rect byAmount:(CGFloat)deltaX { | |
718 NSRect frame = NSOffsetRect(rect, deltaX, 0); | |
719 frame.size.width -= deltaX; | |
720 return frame; | |
721 } | 734 } |
722 | 735 |
723 // Show or hide the home button based on the pref. | 736 // Show or hide the home button based on the pref. |
724 - (void)showOptionalHomeButton { | 737 - (void)showOptionalHomeButton { |
725 // Ignore this message if only showing the URL bar. | 738 // Ignore this message if only showing the URL bar. |
726 if (!hasToolbar_) | 739 if (!hasToolbar_) |
727 return; | 740 return; |
728 BOOL hide = showHomeButton_.GetValue() ? NO : YES; | 741 BOOL hide = showHomeButton_.GetValue() ? NO : YES; |
729 if (hide == [homeButton_ isHidden]) | 742 if (hide == [homeButton_ isHidden]) |
730 return; // Nothing to do, view state matches pref state. | 743 return; // Nothing to do, view state matches pref state. |
731 | 744 |
732 // Always shift the text field by the width of the home button minus one pixel | 745 // Always shift the text field by the width of the home button minus one pixel |
733 // since the frame edges of each button are right on top of each other. When | 746 // since the frame edges of each button are right on top of each other. When |
734 // hiding the button, reverse the direction of the movement (to the left). | 747 // hiding the button, reverse the direction of the movement (to the left). |
735 CGFloat moveX = [homeButton_ frame].size.width; | 748 CGFloat moveX = [homeButton_ frame].size.width; |
736 // Ensure proper spacing between the home button and the location bar. | 749 // Ensure proper spacing between the home button and the location bar. |
737 moveX += kElementPadding; | 750 moveX += kElementPadding; |
738 if (hide) | 751 if (hide) |
739 moveX *= -1; // Reverse the direction of the move. | 752 moveX *= -1; // Reverse the direction of the move. |
740 | 753 CGRect locationBarFrame = [locationBar_ frame]; |
741 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 754 locationBarFrame.size.width -= moveX; |
742 byAmount:moveX]]; | 755 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) |
756 locationBarFrame.origin.x += moveX; | |
757 [locationBar_ setFrame:locationBarFrame]; | |
743 [homeButton_ setHidden:hide]; | 758 [homeButton_ setHidden:hide]; |
744 } | 759 } |
745 | 760 |
746 // Install the app menu buttons. Calling this repeatedly is inexpensive so it | 761 // Install the app menu buttons. Calling this repeatedly is inexpensive so it |
747 // can be done every time the buttons are shown. | 762 // can be done every time the buttons are shown. |
748 - (void)installAppMenu { | 763 - (void)installAppMenu { |
749 if (appMenuController_.get()) | 764 if (appMenuController_.get()) |
750 return; | 765 return; |
751 | 766 |
752 appMenuController_.reset( | 767 appMenuController_.reset( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 selector:@selector(browserActionsContainerWillAnimate:) | 808 selector:@selector(browserActionsContainerWillAnimate:) |
794 name:kBrowserActionsContainerWillAnimate | 809 name:kBrowserActionsContainerWillAnimate |
795 object:browserActionsContainerView_]; | 810 object:browserActionsContainerView_]; |
796 [[NSNotificationCenter defaultCenter] | 811 [[NSNotificationCenter defaultCenter] |
797 addObserver:self | 812 addObserver:self |
798 selector:@selector(adjustBrowserActionsContainerForNewWindow:) | 813 selector:@selector(adjustBrowserActionsContainerForNewWindow:) |
799 name:NSWindowDidBecomeKeyNotification | 814 name:NSWindowDidBecomeKeyNotification |
800 object:[[self view] window]]; | 815 object:[[self view] window]]; |
801 } | 816 } |
802 if (![browserActionsContainerView_ isHidden]) | 817 if (![browserActionsContainerView_ isHidden]) |
803 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 818 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; |
804 } | 819 } |
805 | 820 |
806 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { | 821 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { |
807 CGFloat newHeight = visible ? [ToolbarController locationBarHeight] : 0; | 822 CGFloat newHeight = visible ? [ToolbarController locationBarHeight] : 0; |
808 | 823 |
809 // Perform the animation, which will cause the BrowserWindowController to | 824 // Perform the animation, which will cause the BrowserWindowController to |
810 // resize this view in the browser layout as required. | 825 // resize this view in the browser layout as required. |
811 if (animate) { | 826 if (animate) { |
812 [[self toolbarView] animateToNewHeight:newHeight | 827 [[self toolbarView] animateToNewHeight:newHeight |
813 duration:kToolBarAnimationDuration]; | 828 duration:kToolBarAnimationDuration]; |
814 } else { | 829 } else { |
815 [[self toolbarView] setHeight:newHeight]; | 830 [[self toolbarView] setHeight:newHeight]; |
816 } | 831 } |
817 } | 832 } |
818 | 833 |
819 - (void)adjustBrowserActionsContainerForNewWindow: | 834 - (void)adjustBrowserActionsContainerForNewWindow: |
820 (NSNotification*)notification { | 835 (NSNotification*)notification { |
821 [self toolbarFrameChanged]; | 836 [self toolbarFrameChanged]; |
822 [[NSNotificationCenter defaultCenter] | 837 [[NSNotificationCenter defaultCenter] |
823 removeObserver:self | 838 removeObserver:self |
824 name:NSWindowDidBecomeKeyNotification | 839 name:NSWindowDidBecomeKeyNotification |
825 object:[[self view] window]]; | 840 object:[[self view] window]]; |
826 } | 841 } |
827 | 842 |
828 - (void)browserActionsContainerDragged:(NSNotification*)notification { | 843 - (void)browserActionsContainerDragged:(NSNotification*)notification { |
829 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 844 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; |
830 } | 845 } |
831 | 846 |
832 - (void)browserActionsVisibilityChanged:(NSNotification*)notification { | 847 - (void)browserActionsVisibilityChanged:(NSNotification*)notification { |
833 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 848 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; |
834 } | 849 } |
835 | 850 |
836 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { | 851 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { |
837 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; | 852 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:YES]; |
838 } | 853 } |
839 | 854 |
840 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { | 855 - (void)pinLocationBarBeforeBrowserActionsContainerAndAnimate:(BOOL)animate { |
lgrey
2017/01/12 19:44:19
The change from the previous CL is here
| |
841 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); | 856 CGFloat delta = 0.0; |
842 CGFloat leftDistance = 0.0; | 857 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
858 CGFloat leftEdge = NSMinX([locationBar_ frame]); | |
859 if ([browserActionsContainerView_ isHidden]) { | |
860 delta = leftEdge - NSMaxX([appMenuButton_ frame]) + | |
861 [ToolbarController appMenuPadding] + kButtonInset; | |
862 } else { | |
863 delta = leftEdge - | |
864 NSMaxX([browserActionsContainerView_ animationEndFrame]) + | |
tapted
2017/01/12 19:58:40
it's hard to tell what changed -- it's often helpf
lgrey
2017/01/12 20:04:21
Yup that's it.
Thanks for the heads up on the pat
| |
865 kButtonInset; | |
866 } | |
867 } else { | |
868 CGFloat rightEdge = NSMaxX([locationBar_ frame]); | |
869 if ([browserActionsContainerView_ isHidden]) { | |
870 delta = NSMinX([appMenuButton_ frame]) - | |
871 [ToolbarController appMenuPadding] - kButtonInset - rightEdge; | |
872 } else { | |
873 delta = NSMinX([browserActionsContainerView_ animationEndFrame]) - | |
874 kButtonInset - rightEdge; | |
875 } | |
876 } | |
843 | 877 |
844 if ([browserActionsContainerView_ isHidden]) { | 878 if (delta != 0.0) |
845 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; | 879 [self adjustLocationSizeBy:delta animate:animate]; |
846 leftDistance = edgeXPos - locationBarXPos - | |
847 [ToolbarController appMenuLeftPadding] - kButtonInset; | |
848 } else { | |
849 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - | |
850 locationBarXPos; | |
851 // Equalize the distance between the location bar and the first extension | |
852 // button, and the distance between the location bar and home/reload button. | |
853 leftDistance -= kButtonInset; | |
854 } | |
855 if (leftDistance != 0.0) | |
856 [self adjustLocationSizeBy:leftDistance animate:animate]; | |
857 else | 880 else |
858 [locationBar_ stopAnimation]; | 881 [locationBar_ stopAnimation]; |
859 } | 882 } |
860 | 883 |
861 - (void)maintainMinimumLocationBarWidth { | 884 - (void)maintainMinimumLocationBarWidth { |
862 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 885 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
863 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 886 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
864 if (locationBarAtMinSize_) { | 887 if (locationBarAtMinSize_) { |
865 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; | 888 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; |
866 [self adjustLocationSizeBy:dX animate:NO]; | 889 [self adjustLocationSizeBy:dX animate:NO]; |
867 } | 890 } |
868 } | 891 } |
869 | 892 |
870 - (void)toolbarFrameChanged { | 893 - (void)toolbarFrameChanged { |
871 // Do nothing if the frame changes but no Browser Action Controller is | 894 // Do nothing if the frame changes but no Browser Action Controller is |
872 // present. | 895 // present. |
873 if (!browserActionsController_.get()) | 896 if (!browserActionsController_.get()) |
874 return; | 897 return; |
875 | 898 |
876 if ([browserActionsContainerView_ isAnimating]) { | 899 if ([browserActionsContainerView_ isAnimating]) { |
877 // If the browser actions container is animating, we need to stop it first, | 900 // If the browser actions container is animating, we need to stop it first, |
878 // because the frame it's animating for could be incorrect with the new | 901 // because the frame it's animating for could be incorrect with the new |
879 // bounds (if, for instance, the bookmark bar was added). | 902 // bounds (if, for instance, the bookmark bar was added). |
880 // This will advance to the end of the animation, so we also need to adjust | 903 // This will advance to the end of the animation, so we also need to adjust |
881 // it afterwards. | 904 // it afterwards. |
882 [browserActionsContainerView_ stopAnimation]; | 905 [browserActionsContainerView_ stopAnimation]; |
883 NSRect containerFrame = [browserActionsContainerView_ frame]; | 906 NSRect containerFrame = [browserActionsContainerView_ frame]; |
884 containerFrame.origin.y = [locationBar_ frame].origin.y + kContainerYOffset; | 907 containerFrame.origin.y = [locationBar_ frame].origin.y + kContainerYOffset; |
885 [browserActionsContainerView_ setFrame:containerFrame]; | 908 [browserActionsContainerView_ setFrame:containerFrame]; |
886 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 909 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; |
887 } | 910 } |
888 | 911 |
889 [self maintainMinimumLocationBarWidth]; | 912 [self maintainMinimumLocationBarWidth]; |
890 | 913 |
891 if (locationBarAtMinSize_) { | 914 if (locationBarAtMinSize_) { |
892 // Once the grippy is pinned, leave it until it is explicity un-pinned. | 915 // Once the grippy is pinned, leave it until it is explicity un-pinned. |
893 [browserActionsContainerView_ setGrippyPinned:YES]; | 916 [browserActionsContainerView_ setGrippyPinned:YES]; |
894 NSRect containerFrame = [browserActionsContainerView_ frame]; | 917 NSRect containerFrame = [browserActionsContainerView_ frame]; |
895 // Determine how much the container needs to move in case it's overlapping | 918 // Determine how much the container needs to move in case it's overlapping |
896 // with the location bar. | 919 // with the location bar. |
897 CGFloat dX = NSMaxX([locationBar_ frame]) - containerFrame.origin.x; | 920 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
898 containerFrame = NSOffsetRect(containerFrame, dX, 0); | 921 CGFloat dX = NSMaxX(containerFrame) - NSMinX([locationBar_ frame]); |
899 containerFrame.size.width -= dX; | 922 containerFrame.size.width -= dX; |
923 } else { | |
924 CGFloat dX = NSMaxX([locationBar_ frame]) - containerFrame.origin.x; | |
925 containerFrame = NSOffsetRect(containerFrame, dX, 0); | |
926 } | |
900 [browserActionsContainerView_ setFrame:containerFrame]; | 927 [browserActionsContainerView_ setFrame:containerFrame]; |
901 } else if (!locationBarAtMinSize_ && | 928 } else if (!locationBarAtMinSize_ && |
902 [browserActionsContainerView_ grippyPinned]) { | 929 [browserActionsContainerView_ grippyPinned]) { |
903 // Expand out the container until it hits the saved size, then unpin the | 930 // Expand out the container until it hits the saved size, then unpin the |
904 // grippy. | 931 // grippy. |
905 // Add 0.1 pixel so that it doesn't hit the minimum width codepath above. | 932 // Add 0.1 pixel so that it doesn't hit the minimum width codepath above. |
906 CGFloat dX = NSWidth([locationBar_ frame]) - | 933 CGFloat dX = NSWidth([locationBar_ frame]) - |
907 (kMinimumLocationBarWidth + 0.1); | 934 (kMinimumLocationBarWidth + 0.1); |
908 NSRect containerFrame = [browserActionsContainerView_ frame]; | 935 NSRect containerFrame = [browserActionsContainerView_ frame]; |
909 containerFrame = NSOffsetRect(containerFrame, -dX, 0); | 936 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) |
937 containerFrame = NSOffsetRect(containerFrame, -dX, 0); | |
910 containerFrame.size.width += dX; | 938 containerFrame.size.width += dX; |
911 CGFloat savedContainerWidth = | 939 CGFloat savedContainerWidth = |
912 [browserActionsController_ preferredSize].width(); | 940 [browserActionsController_ preferredSize].width(); |
913 if (NSWidth(containerFrame) >= savedContainerWidth) { | 941 if (NSWidth(containerFrame) >= savedContainerWidth) { |
914 containerFrame = NSOffsetRect(containerFrame, | 942 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
915 NSWidth(containerFrame) - savedContainerWidth, 0); | 943 containerFrame = NSOffsetRect( |
944 containerFrame, NSWidth(containerFrame) - savedContainerWidth, 0); | |
945 } | |
916 containerFrame.size.width = savedContainerWidth; | 946 containerFrame.size.width = savedContainerWidth; |
917 [browserActionsContainerView_ setGrippyPinned:NO]; | 947 [browserActionsContainerView_ setGrippyPinned:NO]; |
918 } | 948 } |
919 [browserActionsContainerView_ setFrame:containerFrame]; | 949 [browserActionsContainerView_ setFrame:containerFrame]; |
920 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 950 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; |
921 } | 951 } |
922 } | 952 } |
923 | 953 |
924 // Hide the back, forward, reload, home, and app menu buttons of the toolbar. | 954 // Hide the back, forward, reload, home, and app menu buttons of the toolbar. |
925 // This allows the location bar to occupy the entire width. There is no way to | 955 // This allows the location bar to occupy the entire width. There is no way to |
926 // undo this operation, and once it is called, no other programmatic changes | 956 // undo this operation, and once it is called, no other programmatic changes |
927 // to the toolbar or location bar width should be made. This message is | 957 // to the toolbar or location bar width should be made. This message is |
928 // invalid if the toolbar is shown or the location bar is hidden. | 958 // invalid if the toolbar is shown or the location bar is hidden. |
929 - (void)showLocationBarOnly { | 959 - (void)showLocationBarOnly { |
930 // -showLocationBarOnly is only ever called once, shortly after | 960 // -showLocationBarOnly is only ever called once, shortly after |
931 // initialization, so the regular buttons should all be visible. | 961 // initialization, so the regular buttons should all be visible. |
932 DCHECK(!hasToolbar_ && hasLocationBar_); | 962 DCHECK(!hasToolbar_ && hasLocationBar_); |
933 DCHECK(![backButton_ isHidden]); | 963 DCHECK(![backButton_ isHidden]); |
934 | 964 |
935 // Ensure the location bar fills the toolbar. | 965 // Ensure the location bar fills the toolbar. |
936 NSRect toolbarFrame = [[self view] frame]; | 966 NSRect toolbarFrame = [[self view] frame]; |
937 toolbarFrame.size.height = [ToolbarController locationBarHeight]; | 967 toolbarFrame.size.height = [ToolbarController locationBarHeight]; |
938 [[self view] setFrame:toolbarFrame]; | 968 [[self view] setFrame:toolbarFrame]; |
939 | 969 |
940 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]), | 970 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]), |
941 [ToolbarController locationBarHeight])]; | 971 [ToolbarController locationBarHeight])]; |
942 | 972 |
943 [backButton_ setHidden:YES]; | 973 [backButton_ setHidden:YES]; |
944 [forwardButton_ setHidden:YES]; | 974 [forwardButton_ setHidden:YES]; |
945 [reloadButton_ setHidden:YES]; | 975 [reloadButton_ setHidden:YES]; |
946 [appMenuButton_ setHidden:YES]; | 976 [appMenuButton_ setHidden:YES]; |
947 [homeButton_ setHidden:YES]; | 977 [homeButton_ setHidden:YES]; |
978 [browserActionsContainerView_ setHidden:YES]; | |
948 } | 979 } |
949 | 980 |
950 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { | 981 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { |
951 // Ensure that the location bar is in its proper place. | 982 // Ensure that the location bar is in its proper place. |
952 NSRect locationFrame = [locationBar_ frame]; | 983 NSRect locationFrame = [locationBar_ frame]; |
953 locationFrame.size.width += dX; | 984 locationFrame.size.width += dX; |
985 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | |
986 locationFrame.origin.x -= dX; | |
954 | 987 |
955 [locationBar_ stopAnimation]; | 988 [locationBar_ stopAnimation]; |
956 | |
957 if (animate) | 989 if (animate) |
958 [locationBar_ animateToFrame:locationFrame]; | 990 [locationBar_ animateToFrame:locationFrame]; |
959 else | 991 else |
960 [locationBar_ setFrame:locationFrame]; | 992 [locationBar_ setFrame:locationFrame]; |
961 } | 993 } |
962 | 994 |
963 - (NSPoint)bookmarkBubblePoint { | 995 - (NSPoint)bookmarkBubblePoint { |
964 if (locationBarView_->IsStarEnabled()) | 996 if (locationBarView_->IsStarEnabled()) |
965 return locationBarView_->GetBubblePointForDecoration( | 997 return locationBarView_->GetBubblePointForDecoration( |
966 locationBarView_->star_decoration()); | 998 locationBarView_->star_decoration()); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1092 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1124 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
1093 // Do nothing. | 1125 // Do nothing. |
1094 } | 1126 } |
1095 | 1127 |
1096 // (URLDropTargetController protocol) | 1128 // (URLDropTargetController protocol) |
1097 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1129 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
1098 return drag_util::IsUnsupportedDropData(profile_, info); | 1130 return drag_util::IsUnsupportedDropData(profile_, info); |
1099 } | 1131 } |
1100 | 1132 |
1101 @end | 1133 @end |
OLD | NEW |