Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / infobars / translate_infobar_base.h
blobff0de35eeb4af7a4ceb638b5ec2fd25dbc28f331
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.
5 #ifndef CHROME_BROWSER_UI_COCOA_INFOBARS_TRANSLATE_INFOBAR_BASE_H_
6 #define CHROME_BROWSER_UI_COCOA_INFOBARS_TRANSLATE_INFOBAR_BASE_H_
8 #import <Cocoa/Cocoa.h>
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h"
13 #include "components/translate/core/browser/options_menu_model.h"
14 #include "components/translate/core/browser/translate_infobar_delegate.h"
15 #include "components/translate/core/common/translate_errors.h"
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_;
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_;
42 // Space between controls in pixels - read from the NIB.
43 CGFloat spaceBetweenControls_;
45 scoped_ptr<translate::OptionsMenuModel> optionsMenuModel_;
48 // Returns the delegate as a TranslateInfoBarDelegate. The return
49 // value can be NULL if the infobar is closing.
50 - (translate::TranslateInfoBarDelegate*)delegate;
52 // Called when the "Show Original" button is pressed.
53 - (IBAction)showOriginal:(id)sender;
55 @end
57 @interface TranslateInfoBarControllerBase (ProtectedAPI)
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;
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;
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;
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;
83 // Shows the array of controls provided by the subclass.
84 - (void)showVisibleControls:(NSArray*)visibleControls;
86 // Hides the OK and Cancel buttons.
87 - (void)removeOkCancelButtons;
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;
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;
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;
105 // Whether or not this infobar should show the options popup.
106 - (BOOL)shouldShowOptionsPopUp;
108 @end // TranslateInfoBarControllerBase (ProtectedAPI)
110 #pragma mark TestingAPI
112 @interface TranslateInfoBarControllerBase (TestingAPI)
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;
119 // Verifies that the layout of the infobar is correct.
120 // Must be implmented by the subclass.
121 - (bool)verifyLayout;
123 // Returns the underlying options menu.
124 - (NSMenu*)optionsMenu;
126 // Returns |translateMessageButton_|, see declaration of member
127 // variable for a full description.
128 - (NSButton*)translateMessageButton;
130 @end // TranslateInfoBarControllerBase (TestingAPI)
133 #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_TRANSLATE_INFOBAR_BASE_H_