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

Side by Side Diff: chrome/browser/cocoa/translate/translate_infobar_base.h

Issue 2815013: Refactor the translate infobars on mac to match the new windows code. (Closed)
Patch Set: Move unittest stuff back to class files Created 10 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_COCOA_TRANSLATE_INFOBAR_BASE_H_
6 #define CHROME_BROWSER_COCOA_TRANSLATE_INFOBAR_BASE_H_
7
8 #import <Cocoa/Cocoa.h>
9 #import "chrome/browser/cocoa/infobar_controller.h"
10
11 #import "base/cocoa_protocols_mac.h"
12 #import "base/scoped_nsobject.h"
13 #include "base/scoped_ptr.h"
14 #include "chrome/browser/translate/languages_menu_model2.h"
15 #include "chrome/browser/translate/options_menu_model2.h"
16 #include "chrome/browser/translate/translate_infobar_delegate2.h"
17 #include "chrome/common/notification_registrar.h"
18 #include "chrome/common/translate_errors.h"
19
20 class TranslateInfoBarMenuModel;
21
22 #pragma mark TranslateInfoBarUtilities helper functions.
23 namespace TranslateInfoBarUtilities {
24
25 // Move the |toMove| view |spacing| pixels before/after the |anchor| view.
26 // |after| signifies the side of |anchor| on which to place |toMove|.
27 void MoveControl(NSView* anchor, NSView* toMove, int spacing, bool after);
28
29 // Vertically center |toMove| in its container.
30 void VerticallyCenterView(NSView *toMove);
31 // Check that the control |before| is ordered visually before the |after|
32 // control.
33 // Also, check that there is space between them.
34 bool VerifyControlOrderAndSpacing(id before, id after);
35
36 // Creates a label control in the style we need for the translate infobar's
37 // labels within |bounds|.
38 NSTextField* CreateLabel(NSRect bounds);
39
40 // Adds an item with the specified properties to |menu|.
41 void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title,
42 int tag, bool enabled, bool checked);
43
44 } // namespace
45
46 // The base class for the three translate infobars. This class does all of the
47 // heavy UI lifting, while deferring to the subclass to tell it what views
48 // should be shown and where. Subclasses need to implement:
49 // - (void)layout;
50 // - (void)loadLabelText;
51 // - (void)visibleControls;
52 // - (bool)verifyLayout; // For testing.
53 @interface TranslateInfoBarControllerBase : InfoBarController<NSMenuDelegate> {
54 @protected
55 scoped_nsobject<NSTextField> label1_;
56 scoped_nsobject<NSTextField> label2_;
57 scoped_nsobject<NSTextField> label3_;
58 scoped_nsobject<NSPopUpButton> fromLanguagePopUp_;
59 scoped_nsobject<NSPopUpButton> toLanguagePopUp_;
60 scoped_nsobject<NSPopUpButton> optionsPopUp_;
61 scoped_nsobject<NSButton> showOriginalButton_;
62 scoped_nsobject<NSButton> tryAgainButton_;
63
64 // In the current locale, are the "from" and "to" language popup menu
65 // flipped from what they'd appear in English.
66 bool swappedLanguagePlaceholders_;
67
68 // Space between controls in pixels - read from the NIB.
69 CGFloat spaceBetweenControls_;
70
71 scoped_ptr<LanguagesMenuModel2> originalLanguageMenuModel_;
72 scoped_ptr<LanguagesMenuModel2> targetLanguageMenuModel_;
73 scoped_ptr<OptionsMenuModel2> optionsMenuModel_;
74 }
75
76 // Returns the delegate as a TranslateInfoBarDelegate.
77 - (TranslateInfoBarDelegate2*)delegate;
78
79 // Called when the "Show Original" button is pressed.
80 - (IBAction)showOriginal:(id)sender;
81
82 @end
83
84 @interface TranslateInfoBarControllerBase (ProtectedAPI)
85
86 // Move all the currently visible views into the correct place for the
87 // current mode.
88 // Must be implemented by the subclass.
89 - (void)layout;
90
91 // Loads the text for the 3 labels. There is only one message, but since
92 // it has controls separating parts of it, it is separated into 3 separate
93 // labels.
94 // Must be implemented by the subclass.
95 - (void)loadLabelText;
96
97 // Returns the controls that are visible in the subclasses infobar. The
98 // default implementation returns an empty array. The controls should
99 // be returned in the order they are displayed, otherwise the layout test
100 // will fail.
101 // Must be implemented by the subclass.
102 - (NSArray*)visibleControls;
103
104 // Shows the array of controls provided by the subclass.
105 - (void)showVisibleControls:(NSArray*)visibleControls;
106
107 // Hides the OK and Cancel buttons.
108 - (void)removeOkCancelButtons;
109
110 // Called when the source or target language selection changes in a menu.
111 // |newLanguageIdx| is the index of the newly selected item in the appropriate
112 // menu.
113 - (void)sourceLanguageModified:(NSInteger)newLanguageIdx;
114 - (void)targetLanguageModified:(NSInteger)newLanguageIdx;
115
116 // Called when an item in one of the toolbar's language or options
117 // menus is selected.
118 - (void)languageMenuChanged:(id)item;
119 - (void)optionsMenuChanged:(id)item;
120
121 // Teardown and rebuild the options menu.
122 - (void)rebuildOptionsMenu;
123
124 @end // TranslateInfoBarControllerBase (ProtectedAPI)
125
126 #pragma mark TestingAPI
127
128 @interface TranslateInfoBarControllerBase (TestingAPI)
129
130 // Verifies that the layout of the infobar is correct.
131 // Must be implmented by the subclass.
132 - (bool)verifyLayout;
133
134 // Returns the underlying options menu.
135 - (NSMenu*)optionsMenu;
136
137 // Returns the "try again" button.
138 - (NSButton*)tryAgainButton;
139
140 @end // TranslateInfoBarControllerBase (TestingAPI)
141
142
143 #endif // CHROME_BROWSER_COCOA_TRANSLATE_INFOBAR_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698