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

Side by Side Diff: chrome/browser/cocoa/translate_infobar.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 #import <Cocoa/Cocoa.h>
6 #import "chrome/browser/cocoa/infobar_controller.h"
7
8 #import "base/cocoa_protocols_mac.h"
9 #import "base/scoped_nsobject.h"
10 #include "base/scoped_ptr.h"
11 #include "chrome/browser/translate/languages_menu_model.h"
12 #include "chrome/browser/translate/options_menu_model.h"
13 #include "chrome/browser/translate/translate_infobars_delegates.h"
14 #include "chrome/common/notification_registrar.h"
15 #include "chrome/common/translate_errors.h"
16
17 class TranslateInfoBarMenuModel;
18 class TranslateNotificationObserverBridge;
19
20 // Draws and maintains Translate Infobar GUI.
21 // The translate bar can be in one of 3 states:
22 // 1. "Before Translate" - source language popup and translate/cancel buttons
23 // visible.
24 // 2. "Translating" - "Translating..." status text visible in address bar.
25 // 3. "After Translation" - source & target language popups visible.
26 //
27 // The following state transitions are supported:
28 // 1->{2,3}
29 // 2<->3
30 // i.e. Once you've transitioned out of "Before Translate" mode you can't switch
31 // back, however all other state transitions are supported.
32 //
33 // The GUI uses popup menus interspersed in a text label. For localization
34 // purposes this means we potentially need 3 labels to display the UI (the 3rd
35 // is only visible in certain locales).
36 @interface TranslateInfoBarController : InfoBarController<NSMenuDelegate> {
37 @protected
38 // Infobar keeps track of the state it is displaying, which should match that
39 // in the TranslateInfoBarDelegate. UI needs to keep track separately because
40 // infobar may receive PAGE_TRANSLATED notifications before delegate does, in
41 // which case, delegate's state is not updated and hence can't be used to
42 // update display. After the notification is sent out to all observers, both
43 // infobar and delegate would end up with the same state.
44 TranslateInfoBarDelegate::TranslateState state_;
45
46 // Is a translation currently in progress.
47 bool translationPending_;
48
49 scoped_nsobject<NSTextField> label1_;
50 scoped_nsobject<NSTextField> label2_;
51 scoped_nsobject<NSTextField> label3_;
52 scoped_nsobject<NSTextField> translatingLabel_;
53 scoped_nsobject<NSPopUpButton> fromLanguagePopUp_;
54 scoped_nsobject<NSPopUpButton> toLanguagePopUp_;
55 scoped_nsobject<NSPopUpButton> optionsPopUp_;
56 scoped_nsobject<NSButton> showOriginalButton_;
57 scoped_nsobject<NSButton> tryAgainButton_;
58
59 // In the current locale, are the "from" and "to" language popup menu
60 // flipped from what they'd appear in English.
61 bool swappedLanguagePlaceholders_;
62
63 // Space between controls in pixels - read from the NIB.
64 CGFloat spaceBetweenControls_;
65 int numLabelsDisplayed_;
66
67 scoped_ptr<LanguagesMenuModel> original_language_menu_model_;
68 scoped_ptr<LanguagesMenuModel> target_language_menu_model_;
69 scoped_ptr<OptionsMenuModel> options_menu_model_;
70 scoped_ptr<TranslateInfoBarMenuModel> menu_model_;
71 scoped_ptr<TranslateNotificationObserverBridge> observer_bridge_;
72 }
73
74 // Called when the "Show Original" button is pressed.
75 - (IBAction)showOriginal:(id)sender;
76
77 @end
78
79 @interface TranslateInfoBarController (TestingAPI)
80
81 // Main function to update the toolbar graphic state and data model after
82 // the state has changed.
83 // Controls are moved around as needed and visibility changed to match the
84 // current state.
85 - (void)updateState:(TranslateInfoBarDelegate::TranslateState)newState
86 translationPending:(bool)newTranslationPending
87 error:(TranslateErrors::Type)error;
88
89
90 // Called when the source or target language selection changes in a menu.
91 // |newLanguageIdx| is the index of the newly selected item in the appropriate
92 // menu.
93 - (void)sourceLanguageModified:(NSInteger)newLanguageIdx;
94 - (void)targetLanguageModified:(NSInteger)newLanguageIdx;
95
96 // Called when an item in one of the toolbar's menus is selected.
97 - (void)menuItemSelected:(id)item;
98
99 // Returns the underlying options menu.
100 - (NSMenu*)optionsMenu;
101
102 // Returns the "try again" button.
103 - (NSButton*)tryAgainButton;
104
105 // The TranslateInfoBarController's internal idea of the current state.
106 - (TranslateInfoBarDelegate::TranslateState)state;
107
108 // Verifies that the layout of the infobar is correct for |state|.
109 - (bool)verifyLayout:(TranslateInfoBarDelegate::TranslateState)state
110 translationPending:(bool)translationPending;
111
112 // Teardown and rebuild the options menu.
113 - (void)rebuildOptionsMenu;
114
115 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/translate/translate_message_infobar_controller.mm ('k') | chrome/browser/cocoa/translate_infobar.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698