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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_COCOA_INFOBARS_TRANSLATE_INFOBAR_BASE_H_ 6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_TRANSLATE_INFOBAR_BASE_H_ 7 8 #import <Cocoa/Cocoa.h> 9 10 #import "base/mac/scoped_nsobject.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/translate/options_menu_model.h" 13 #include "chrome/browser/translate/translate_infobar_delegate.h" 14 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" 15 #include "chrome/common/translate/translate_errors.h" 16 17 // The base class for the three translate infobars. This class does all of the 18 // heavy UI lifting, while deferring to the subclass to tell it what views 19 // should be shown and where. Subclasses need to implement: 20 // - (void)layout; 21 // - (void)loadLabelText; 22 // - (void)visibleControls; 23 // - (bool)verifyLayout; // For testing. 24 @interface TranslateInfoBarControllerBase : InfoBarController<NSMenuDelegate> { 25 @protected 26 base::scoped_nsobject<NSTextField> label1_; 27 base::scoped_nsobject<NSTextField> label2_; 28 base::scoped_nsobject<NSTextField> label3_; 29 base::scoped_nsobject<NSPopUpButton> fromLanguagePopUp_; 30 base::scoped_nsobject<NSPopUpButton> toLanguagePopUp_; 31 base::scoped_nsobject<NSPopUpButton> optionsPopUp_; 32 base::scoped_nsobject<NSButton> showOriginalButton_; 33 // This is the button used in the translate message infobar. It can either be 34 // a "Try Again" button, or a "Show Original" button in the case that the 35 // page was translated from an unknown language. 36 base::scoped_nsobject<NSButton> translateMessageButton_; 37 38 // In the current locale, are the "from" and "to" language popup menu 39 // flipped from what they'd appear in English. 40 bool swappedLanguagePlaceholders_; 41 42 // Space between controls in pixels - read from the NIB. 43 CGFloat spaceBetweenControls_; 44 45 scoped_ptr<OptionsMenuModel> optionsMenuModel_; 46 } 47 48 // Returns the delegate as a TranslateInfoBarDelegate. The return 49 // value can be NULL if the infobar is closing. 50 - (TranslateInfoBarDelegate*)delegate; 51 52 // Called when the "Show Original" button is pressed. 53 - (IBAction)showOriginal:(id)sender; 54 55 @end 56 57 @interface TranslateInfoBarControllerBase (ProtectedAPI) 58 59 // Resizes or hides the options button based on how much space is available 60 // so that it doesn't overlap other buttons. 61 // lastView is the rightmost view, the first one that the options button 62 // would overlap with. 63 - (void)adjustOptionsButtonSizeAndVisibilityForView:(NSView*)lastView; 64 65 // Move all the currently visible views into the correct place for the 66 // current mode. 67 // Must be implemented by the subclass. 68 - (void)layout; 69 70 // Loads the text for the 3 labels. There is only one message, but since 71 // it has controls separating parts of it, it is separated into 3 separate 72 // labels. 73 // Must be implemented by the subclass. 74 - (void)loadLabelText; 75 76 // Returns the controls that are visible in the subclasses infobar. The 77 // default implementation returns an empty array. The controls should 78 // be returned in the order they are displayed, otherwise the layout test 79 // will fail. 80 // Must be implemented by the subclass. 81 - (NSArray*)visibleControls; 82 83 // Shows the array of controls provided by the subclass. 84 - (void)showVisibleControls:(NSArray*)visibleControls; 85 86 // Hides the OK and Cancel buttons. 87 - (void)removeOkCancelButtons; 88 89 // Called when the source or target language selection changes in a menu. 90 // |newLanguageIdx| is the index of the newly selected item in the appropriate 91 // menu. 92 - (void)sourceLanguageModified:(NSInteger)newLanguageIdx; 93 - (void)targetLanguageModified:(NSInteger)newLanguageIdx; 94 95 // Called when an item in one of the toolbar's language or options 96 // menus is selected. 97 - (void)languageMenuChanged:(id)item; 98 - (void)optionsMenuChanged:(id)item; 99 100 // Teardown and rebuild the options menu. When the infobar is small, the 101 // options menu is shrunk to just a drop down arrow, so the title needs 102 // to be empty. 103 - (void)rebuildOptionsMenu:(BOOL)hideTitle; 104 105 // Whether or not this infobar should show the options popup. 106 - (BOOL)shouldShowOptionsPopUp; 107 108 @end // TranslateInfoBarControllerBase (ProtectedAPI) 109 110 #pragma mark TestingAPI 111 112 @interface TranslateInfoBarControllerBase (TestingAPI) 113 114 // All the controls used in any of the translate states. 115 // This is used for verifying layout and for setting the 116 // correct styles on each button. 117 - (NSArray*)allControls; 118 119 // Verifies that the layout of the infobar is correct. 120 // Must be implmented by the subclass. 121 - (bool)verifyLayout; 122 123 // Returns the underlying options menu. 124 - (NSMenu*)optionsMenu; 125 126 // Returns |translateMessageButton_|, see declaration of member 127 // variable for a full description. 128 - (NSButton*)translateMessageButton; 129 130 @end // TranslateInfoBarControllerBase (TestingAPI) 131 132 133 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_TRANSLATE_INFOBAR_BASE_H_ 134