15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_COCOA_TOOLBAR_TOOLBAR_CONTROLLER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_COCOA_TOOLBAR_TOOLBAR_CONTROLLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/mac/scoped_nsobject.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_member.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import "chrome/browser/ui/cocoa/command_observer_bridge.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import "chrome/browser/ui/cocoa/url_drop_target.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import "chrome/browser/ui/cocoa/view_resizer.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#import "ui/base/cocoa/tracking_area.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class AutocompleteTextField; 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class AutocompleteTextFieldEditor; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class BackForwardMenuController; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Browser; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class BrowserActionsContainerView; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class BrowserActionsController; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CommandUpdater; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LocationBarViewMac; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class MenuButton; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class ReloadButton; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class ToolbarButton; 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class WrenchMenuController; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ToolbarControllerInternal { 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NotificationBridge; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A controller for the toolbar in the browser window. Manages 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// updating the state for location bar and back/fwd/reload/go buttons. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Manages the bookmark bar and its position in the window relative to 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the web content view. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface ToolbarController : NSViewController<CommandObserverProtocol, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLDropTargetController> { 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @protected 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The ordering is important for unit tests. If new items are added or the 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ordering is changed, make sure to update |-toolbarViews| and the 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // corresponding enum in the unit tests. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet MenuButton* backButton_; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet MenuButton* forwardButton_; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet ReloadButton* reloadButton_; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet ToolbarButton* homeButton_; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet MenuButton* wrenchButton_; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet AutocompleteTextField* locationBar_; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IBOutlet BrowserActionsContainerView* browserActionsContainerView_; 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @private 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CommandUpdater* commands_; // weak, one per window 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile_; // weak, one per window 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Browser* browser_; // weak, one per window 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<CommandObserverBridge> commandObserver_; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<LocationBarViewMac> locationBarView_; 65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::scoped_nsobject<AutocompleteTextFieldEditor> 66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autocompleteTextFieldEditor_; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) id<ViewResizer> resizeDelegate_; // weak 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::scoped_nsobject<BackForwardMenuController> backMenuController_; 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::scoped_nsobject<BackForwardMenuController> forwardMenuController_; 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::scoped_nsobject<BrowserActionsController> browserActionsController_; 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Lazily-instantiated menu controller. 73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::scoped_nsobject<WrenchMenuController> wrenchMenuController_; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used for monitoring the optional toolbar button prefs. 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<ToolbarControllerInternal::NotificationBridge> notificationBridge_; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BooleanPrefMember showHomeButton_; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL hasToolbar_; // If NO, we may have only the location bar. 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL hasLocationBar_; // If |hasToolbar_| is YES, this must also be YES. 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BOOL locationBarAtMinSize_; // If the location bar is at the minimum size. 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We have an extra retain in the locationBar_. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // See comments in awakeFromNib for more info. 84eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::scoped_nsobject<AutocompleteTextField> locationBarRetainer_; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tracking area for mouse enter/exit/moved in the toolbar. 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedCrTrackingArea trackingArea_; 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We retain/release the hover button since interaction with the 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // button may make it go away (e.g. delete menu option over a 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bookmark button). Thus this variable is not weak. The 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // hoveredButton_ is required to have an NSCell that responds to 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // setMouseInside:animate:. 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NSButton* hoveredButton_; 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Initialize the toolbar and register for command updates. The profile is 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// needed for initializing the location bar. The browser is needed for 993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// the toolbar model and back/forward menus. 1003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)- (id)initWithCommands:(CommandUpdater*)commands 1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile:(Profile*)profile 1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) browser:(Browser*)browser 1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) resizeDelegate:(id<ViewResizer>)resizeDelegate; 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the C++ bridge object representing the location bar for this tab. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (LocationBarViewMac*)locationBarBridge; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Called by the Window delegate so we can provide a custom field editor if 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// needed. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note that this may be called for objects unrelated to the toolbar. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// returns nil if we don't want to override the custom field editor for |obj|. 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (id)customFieldEditorForObject:(id)obj; 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Make the location bar the first responder, if possible. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)focusLocationBar:(BOOL)selectAll; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Forces the toolbar (and transitively the location bar) to update its current 1183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// state. If |tab| is non-NULL, we're switching (back?) to this tab and should 1193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// restore any previous location bar state (such as user editing) as well. 1203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)- (void)updateToolbarWithContents:(content::WebContents*)tab; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Sets whether or not the current page in the frontmost tab is bookmarked. 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)setStarredState:(BOOL)isStarred; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Sets whether or not the current page is translated. 126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)- (void)setTranslateIconLit:(BOOL)on; 127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Happens when the zoom for the active tab changes, the active tab switches, or 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// a new tab or browser window is created. |canShowBubble| indicates if it is 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// appropriate to show a zoom bubble for the change. 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)zoomChangedForActiveTab:(BOOL)canShowBubble; 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Called to update the loading state. Handles updating the go/stop 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// button state. |force| is set if the update is due to changing 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// tabs, as opposed to the page-load finishing. See comment in 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// reload_button.h. 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)setIsLoading:(BOOL)isLoading force:(BOOL)force; 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Allow turning off the toolbar (but we may keep the location bar without a 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// surrounding toolbar). If |toolbar| is YES, the value of |hasLocationBar| is 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ignored. This changes the behavior of other methods, like |-view|. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)setHasToolbar:(BOOL)toolbar hasLocationBar:(BOOL)locBar; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Point on the star icon for the bookmark bubble to be - in the 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// associated window's coordinate system. 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (NSPoint)bookmarkBubblePoint; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 148a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Point on the translate icon fot the Translate bubble. 149a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)- (NSPoint)translateBubblePoint; 150a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the desired toolbar height for the given compression factor. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight; 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set the opacity of the divider (the line at the bottom) *if* we have a 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |ToolbarView| (0 means don't show it); no-op otherwise. 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)setDividerOpacity:(CGFloat)opacity; 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Create and add the Browser Action buttons to the toolbar view. 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)createBrowserActionButtons; 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Return the BrowserActionsController for this toolbar. 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (BrowserActionsController*)browserActionsController; 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the wrench button. 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (NSView*)wrenchButton; 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A set of private methods used by subclasses. Do not call these directly 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// unless a subclass of ToolbarController. 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface ToolbarController(ProtectedMethods) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Designated initializer which takes a nib name in order to allow subclasses 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to load a different nib file. 1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)- (id)initWithCommands:(CommandUpdater*)commands 1753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) profile:(Profile*)profile 1763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) browser:(Browser*)browser 1773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) resizeDelegate:(id<ViewResizer>)resizeDelegate 1783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) nibFileNamed:(NSString*)nibName; 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A set of private methods used by tests, in the absence of "friends" in ObjC. 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface ToolbarController(PrivateTestMethods) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns an array of views in the order of the outlets above. 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (NSArray*)toolbarViews; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)showOptionalHomeButton; 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)installWrenchMenu; 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (WrenchMenuController*)wrenchMenuController; 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Return a hover button for the current event. 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (NSButton*)hoverButtonForEvent:(NSEvent*)theEvent; 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_COCOA_TOOLBAR_TOOLBAR_CONTROLLER_H_ 193