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

Side by Side Diff: chrome/browser/cocoa/toolbar_controller.mm

Issue 606079: [Mac] Adds grippys to the left side of the Browser Actions container to resiz... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/extensions/browser_actions_controller.mm ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cocoa/toolbar_controller.h" 5 #import "chrome/browser/cocoa/toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/l10n_util_mac.h" 9 #include "app/l10n_util_mac.h"
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
11 #include "base/nsimage_cache_mac.h" 11 #include "base/nsimage_cache_mac.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "base/gfx/rect.h" 13 #include "base/gfx/rect.h"
14 #include "chrome/app/chrome_dll_resource.h" 14 #include "chrome/app/chrome_dll_resource.h"
15 #include "chrome/browser/app_menu_model.h" 15 #include "chrome/browser/app_menu_model.h"
16 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 16 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
17 #include "chrome/browser/browser.h" 17 #include "chrome/browser/browser.h"
18 #include "chrome/browser/bubble_positioner.h" 18 #include "chrome/browser/bubble_positioner.h"
19 #import "chrome/browser/cocoa/autocomplete_text_field.h" 19 #import "chrome/browser/cocoa/autocomplete_text_field.h"
20 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" 20 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h"
21 #import "chrome/browser/cocoa/back_forward_menu_controller.h" 21 #import "chrome/browser/cocoa/back_forward_menu_controller.h"
22 #import "chrome/browser/cocoa/background_gradient_view.h" 22 #import "chrome/browser/cocoa/background_gradient_view.h"
23 #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h" 23 #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h"
24 #import "chrome/browser/cocoa/extensions/browser_action_button.h" 24 #import "chrome/browser/cocoa/extensions/browser_action_button.h"
25 #import "chrome/browser/cocoa/extensions/browser_actions_container_view.h"
25 #import "chrome/browser/cocoa/extensions/browser_actions_controller.h" 26 #import "chrome/browser/cocoa/extensions/browser_actions_controller.h"
26 #import "chrome/browser/cocoa/gradient_button_cell.h" 27 #import "chrome/browser/cocoa/gradient_button_cell.h"
27 #import "chrome/browser/cocoa/location_bar_view_mac.h" 28 #import "chrome/browser/cocoa/location_bar_view_mac.h"
28 #import "chrome/browser/cocoa/menu_button.h" 29 #import "chrome/browser/cocoa/menu_button.h"
29 #import "chrome/browser/cocoa/menu_controller.h" 30 #import "chrome/browser/cocoa/menu_controller.h"
30 #import "chrome/browser/cocoa/toolbar_view.h" 31 #import "chrome/browser/cocoa/toolbar_view.h"
31 #include "chrome/browser/net/url_fixer_upper.h" 32 #include "chrome/browser/net/url_fixer_upper.h"
32 #include "chrome/browser/page_menu_model.h" 33 #include "chrome/browser/page_menu_model.h"
33 #include "chrome/browser/profile.h" 34 #include "chrome/browser/profile.h"
34 #include "chrome/browser/search_engines/template_url_model.h" 35 #include "chrome/browser/search_engines/template_url_model.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 bubblePositioner_.get(), 216 bubblePositioner_.get(),
216 commands_, toolbarModel_, 217 commands_, toolbarModel_,
217 profile_, browser_)); 218 profile_, browser_));
218 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 219 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
219 [[NSNotificationCenter defaultCenter] 220 [[NSNotificationCenter defaultCenter]
220 addObserver:self 221 addObserver:self
221 selector:@selector(windowResized) 222 selector:@selector(windowResized)
222 name:NSWindowDidResizeNotification 223 name:NSWindowDidResizeNotification
223 object:[[self view] window]]; 224 object:[[self view] window]];
224 // Register pref observers for the optional home and page/options buttons 225 // Register pref observers for the optional home and page/options buttons
225 // and then add them to the toolbar them based on those prefs. 226 // and then add them to the toolbar based on those prefs.
226 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self)); 227 prefObserver_.reset(new ToolbarControllerInternal::PrefObserverBridge(self));
227 PrefService* prefs = profile_->GetPrefs(); 228 PrefService* prefs = profile_->GetPrefs();
228 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get()); 229 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get());
229 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs, 230 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs,
230 prefObserver_.get()); 231 prefObserver_.get());
231 [self showOptionalHomeButton]; 232 [self showOptionalHomeButton];
232 [self showOptionalPageWrenchButtons]; 233 [self showOptionalPageWrenchButtons];
233 234
234 // Create the controllers for the back/forward menus. 235 // Create the controllers for the back/forward menus.
235 backMenuController_.reset([[BackForwardMenuController alloc] 236 backMenuController_.reset([[BackForwardMenuController alloc]
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 return; // Nothing to do, view state matches pref state. 570 return; // Nothing to do, view state matches pref state.
570 571
571 // Shift the go button and resize the text field by the width of the 572 // Shift the go button and resize the text field by the width of the
572 // page/wrench buttons plus two times the gap width. If we're showing the 573 // page/wrench buttons plus two times the gap width. If we're showing the
573 // buttons, we have to reverse the direction of movement (to the left). Unlike 574 // buttons, we have to reverse the direction of movement (to the left). Unlike
574 // the home button above, we only ever have to resize the text field, we don't 575 // the home button above, we only ever have to resize the text field, we don't
575 // have to move it. 576 // have to move it.
576 CGFloat moveX = 2 * [self interButtonSpacing] + NSWidth([pageButton_ frame]) + 577 CGFloat moveX = 2 * [self interButtonSpacing] + NSWidth([pageButton_ frame]) +
577 NSWidth([wrenchButton_ frame]); 578 NSWidth([wrenchButton_ frame]);
578 579
579 // Adjust for the extra unit of inter-button spacing added when the page and
580 // wrench buttons are hidden.
581 if ([browserActionsController_ visibleButtonCount] > 0)
582 moveX -= [self interButtonSpacing];
583
584 if (!hide) 580 if (!hide)
585 moveX *= -1; // Reverse the direction of the move. 581 moveX *= -1; // Reverse the direction of the move.
586 582
587 [self adjustLocationAndGoPositionsBy:moveX]; 583 [self adjustLocationAndGoPositionsBy:moveX];
588 [browserActionsContainerView_ setFrame:NSOffsetRect( 584 [browserActionsContainerView_ setFrame:NSOffsetRect(
589 [browserActionsContainerView_ frame], moveX, 0)]; 585 [browserActionsContainerView_ frame], moveX, 0)];
590 586
587 [browserActionsContainerView_ setRightBorderShown:!hide];
591 [pageButton_ setHidden:hide]; 588 [pageButton_ setHidden:hide];
592 [wrenchButton_ setHidden:hide]; 589 [wrenchButton_ setHidden:hide];
593 } 590 }
594 591
595 - (void)prefChanged:(std::wstring*)prefName { 592 - (void)prefChanged:(std::wstring*)prefName {
596 if (!prefName) return; 593 if (!prefName) return;
597 if (*prefName == prefs::kShowHomeButton) { 594 if (*prefName == prefs::kShowHomeButton) {
598 [self showOptionalHomeButton]; 595 [self showOptionalHomeButton];
599 } else if (*prefName == prefs::kShowPageOptionsButtons) { 596 } else if (*prefName == prefs::kShowPageOptionsButtons) {
600 [self showOptionalPageWrenchButtons]; 597 [self showOptionalPageWrenchButtons];
601 } 598 }
602 } 599 }
603 600
604 - (void)createBrowserActionButtons { 601 - (void)createBrowserActionButtons {
605 [browserActionsController_ createButtons]; 602 [browserActionsController_ createButtons];
606 [self showOrHideBrowserActionButtons]; 603 [self showOrHideBrowserActionButtons];
604 BOOL rightBorderShown = !([pageButton_ isHidden] && [wrenchButton_ isHidden]);
605 [browserActionsContainerView_ setRightBorderShown:rightBorderShown];
607 } 606 }
608 607
609 - (void)showOrHideBrowserActionButtons { 608 - (void)showOrHideBrowserActionButtons {
610 // TODO(andybons): This is ugly as sin and hard to follow. Fix it up. 609 // TODO(andybons): This is ugly as sin and hard to follow. Fix it up.
611 610
612 int buttonCount = [browserActionsController_ buttonCount]; 611 int buttonCount = [browserActionsController_ buttonCount];
613 if (buttonCount == 0 || !hasToolbar_) 612 if (buttonCount == 0 || !hasToolbar_)
614 return; 613 return;
615 614
616 CGFloat curWidth = NSWidth([[[self view] window] frame]); 615 CGFloat curWidth = NSWidth([[[self view] window] frame]);
(...skipping 30 matching lines...) Expand all
647 return; 646 return;
648 BrowserActionButton* button = [[browserActionsContainerView_ subviews] 647 BrowserActionButton* button = [[browserActionsContainerView_ subviews]
649 objectAtIndex:visibleCount + arrayOffset]; 648 objectAtIndex:visibleCount + arrayOffset];
650 [button setHidden:hide]; 649 [button setHidden:hide];
651 [self browserActionsChanged]; 650 [self browserActionsChanged];
652 --delta; 651 --delta;
653 } 652 }
654 } 653 }
655 654
656 - (void)browserActionsChanged { 655 - (void)browserActionsChanged {
657 // Calculate the new width. 656 CGFloat width = [browserActionsController_ idealContainerWidth];
658 int buttonCount = [browserActionsController_ visibleButtonCount];
659
660 CGFloat width = 0.0;
661 if (buttonCount > 0)
662 width = buttonCount * (kBrowserActionWidth + kBrowserActionButtonPadding);
663
664 NSRect containerFrame = [browserActionsContainerView_ frame]; 657 NSRect containerFrame = [browserActionsContainerView_ frame];
665 CGFloat buttonSpacing = [self interButtonSpacing];
666 CGFloat dX = containerFrame.size.width - width; 658 CGFloat dX = containerFrame.size.width - width;
667 containerFrame.size.width = width; 659 containerFrame.size.width = width;
668 660
669 bool addingButton = (dX < 0);
670 // If a button is being added, add spacing inward by negating the value.
671 if (addingButton)
672 buttonSpacing *= -1;
673
674 // If the first button is being added or the last button is being removed,
675 // then account for the right padding it will need.
676 if ((buttonCount == 1 && addingButton) ||
677 (buttonCount == 0 && !addingButton)) {
678 dX += buttonSpacing;
679 // The offset of the buttons from the right side will be one button spacing
680 // unit more than if the wrench and page buttons were shown.
681 if ([pageButton_ isHidden] && [wrenchButton_ isHidden]) {
682 dX += buttonSpacing;
683 }
684 }
685
686 [browserActionsContainerView_ setFrame:NSOffsetRect(containerFrame, dX, 0)]; 661 [browserActionsContainerView_ setFrame:NSOffsetRect(containerFrame, dX, 0)];
687 [self adjustLocationAndGoPositionsBy:dX]; 662 [self adjustLocationAndGoPositionsBy:dX];
688 } 663 }
689 664
690 - (void)adjustLocationAndGoPositionsBy:(CGFloat)dX { 665 - (void)adjustLocationAndGoPositionsBy:(CGFloat)dX {
691 [goButton_ setFrame:NSOffsetRect([goButton_ frame], dX, 0)]; 666 [goButton_ setFrame:NSOffsetRect([goButton_ frame], dX, 0)];
692 NSRect locationFrame = [locationBar_ frame]; 667 NSRect locationFrame = [locationBar_ frame];
693 locationFrame.size.width += dX; 668 locationFrame.size.width += dX;
694 [locationBar_ setFrame:locationFrame]; 669 [locationBar_ setFrame:locationFrame];
695 } 670 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { 797 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point {
823 // Do nothing. 798 // Do nothing.
824 } 799 }
825 800
826 // (URLDropTargetController protocol) 801 // (URLDropTargetController protocol)
827 - (void)hideDropURLsIndicatorInView:(NSView*)view { 802 - (void)hideDropURLsIndicatorInView:(NSView*)view {
828 // Do nothing. 803 // Do nothing.
829 } 804 }
830 805
831 @end 806 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/extensions/browser_actions_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698