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

Side by Side Diff: chrome/browser/ui/cocoa/speech_recognition_window_controller.mm

Issue 9568002: Renamed speech input implementation from to speech_recognition_*. The namespace has been renamed fr… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased from master. Created 8 years, 9 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "speech_input_window_controller.h" 5 #import "speech_recognition_window_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/ui/cocoa/info_bubble_view.h" 9 #include "chrome/browser/ui/cocoa/info_bubble_view.h"
10 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h" 11 #include "grit/theme_resources.h"
12 #import "skia/ext/skia_utils_mac.h" 12 #import "skia/ext/skia_utils_mac.h"
13 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 13 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
14 #include "ui/base/l10n/l10n_util_mac.h" 14 #include "ui/base/l10n/l10n_util_mac.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/image/image.h" 16 #include "ui/gfx/image/image.h"
17 17
18 const int kBubbleControlVerticalSpacing = 10; // Space between controls. 18 const int kBubbleControlVerticalSpacing = 10; // Space between controls.
19 const int kBubbleHorizontalMargin = 5; // Space on either sides of controls. 19 const int kBubbleHorizontalMargin = 5; // Space on either sides of controls.
20 const int kInstructionLabelMaxWidth = 150; 20 const int kInstructionLabelMaxWidth = 150;
21 21
22 @interface SpeechInputWindowController (Private) 22 @interface SpeechRecognitionWindowController (Private)
23 - (NSSize)calculateContentSize; 23 - (NSSize)calculateContentSize;
24 - (void)layout:(NSSize)size; 24 - (void)layout:(NSSize)size;
25 @end 25 @end
26 26
27 @implementation SpeechInputWindowController 27 @implementation SpeechRecognitionWindowController
28 28
29 - (id)initWithParentWindow:(NSWindow*)parentWindow 29 - (id)initWithParentWindow:(NSWindow*)parentWindow
30 delegate:(SpeechInputBubbleDelegate*)delegate 30 delegate:(SpeechRecognitionBubbleDelegate*)delegate
31 anchoredAt:(NSPoint)anchoredAt { 31 anchoredAt:(NSPoint)anchoredAt {
32 anchoredAt.y += info_bubble::kBubbleArrowHeight / 2.0; 32 anchoredAt.y += info_bubble::kBubbleArrowHeight / 2.0;
33 if ((self = [super initWithWindowNibPath:@"SpeechInputBubble" 33 if ((self = [super initWithWindowNibPath:@"SpeechRecognitionBubble"
34 parentWindow:parentWindow 34 parentWindow:parentWindow
35 anchoredAt:anchoredAt])) { 35 anchoredAt:anchoredAt])) {
36 DCHECK(delegate); 36 DCHECK(delegate);
37 delegate_ = delegate; 37 delegate_ = delegate;
38 displayMode_ = SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP; 38 displayMode_ = SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP;
39 } 39 }
40 return self; 40 return self;
41 } 41 }
42 42
43 - (void)awakeFromNib { 43 - (void)awakeFromNib {
44 [super awakeFromNib]; 44 [super awakeFromNib];
45 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; 45 [[self bubble] setArrowLocation:info_bubble::kTopLeft];
46 } 46 }
47 47
48 - (IBAction)cancel:(id)sender { 48 - (IBAction)cancel:(id)sender {
49 delegate_->InfoBubbleButtonClicked(SpeechInputBubble::BUTTON_CANCEL); 49 delegate_->InfoBubbleButtonClicked(SpeechRecognitionBubble::BUTTON_CANCEL);
50 } 50 }
51 51
52 - (IBAction)tryAgain:(id)sender { 52 - (IBAction)tryAgain:(id)sender {
53 delegate_->InfoBubbleButtonClicked(SpeechInputBubble::BUTTON_TRY_AGAIN); 53 delegate_->InfoBubbleButtonClicked(SpeechRecognitionBubble::BUTTON_TRY_AGAIN);
54 } 54 }
55 55
56 - (IBAction)micSettings:(id)sender { 56 - (IBAction)micSettings:(id)sender {
57 [[NSWorkspace sharedWorkspace] openFile: 57 [[NSWorkspace sharedWorkspace] openFile:
58 @"/System/Library/PreferencePanes/Sound.prefPane"]; 58 @"/System/Library/PreferencePanes/Sound.prefPane"];
59 } 59 }
60 60
61 // Calculate the window dimensions to reflect the sum height and max width of 61 // Calculate the window dimensions to reflect the sum height and max width of
62 // all controls, with appropriate spacing between and around them. The returned 62 // all controls, with appropriate spacing between and around them. The returned
63 // size is in view coordinates. 63 // size is in view coordinates.
64 - (NSSize)calculateContentSize { 64 - (NSSize)calculateContentSize {
65 [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; 65 [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_];
66 [GTMUILocalizerAndLayoutTweaker sizeToFitView:tryAgainButton_]; 66 [GTMUILocalizerAndLayoutTweaker sizeToFitView:tryAgainButton_];
67 [GTMUILocalizerAndLayoutTweaker sizeToFitView:micSettingsButton_]; 67 [GTMUILocalizerAndLayoutTweaker sizeToFitView:micSettingsButton_];
68 NSSize cancelSize = [cancelButton_ bounds].size; 68 NSSize cancelSize = [cancelButton_ bounds].size;
69 NSSize tryAgainSize = [tryAgainButton_ bounds].size; 69 NSSize tryAgainSize = [tryAgainButton_ bounds].size;
70 CGFloat newHeight = cancelSize.height + kBubbleControlVerticalSpacing; 70 CGFloat newHeight = cancelSize.height + kBubbleControlVerticalSpacing;
71 CGFloat newWidth = cancelSize.width; 71 CGFloat newWidth = cancelSize.width;
72 if (![tryAgainButton_ isHidden]) 72 if (![tryAgainButton_ isHidden])
73 newWidth += tryAgainSize.width; 73 newWidth += tryAgainSize.width;
74 74
75 // The size of the bubble in warm up mode is fixed to be the same as in 75 // The size of the bubble in warm up mode is fixed to be the same as in
76 // recording mode, so from warm up it can transition to recording without any 76 // recording mode, so from warm up it can transition to recording without any
77 // UI jank. 77 // UI jank.
78 bool isWarmUp = (displayMode_ == 78 bool isWarmUp = (displayMode_ ==
79 SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP); 79 SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP);
80 80
81 if (![iconImage_ isHidden]) { 81 if (![iconImage_ isHidden]) {
82 NSSize size = [[iconImage_ image] size]; 82 NSSize size = [[iconImage_ image] size];
83 if (isWarmUp) { 83 if (isWarmUp) {
84 NSImage* volumeIcon = 84 NSImage* volumeIcon =
85 ResourceBundle::GetSharedInstance().GetNativeImageNamed( 85 ResourceBundle::GetSharedInstance().GetNativeImageNamed(
86 IDR_SPEECH_INPUT_MIC_EMPTY); 86 IDR_SPEECH_INPUT_MIC_EMPTY);
87 size = [volumeIcon size]; 87 size = [volumeIcon size];
88 } 88 }
89 newHeight += size.height; 89 newHeight += size.height;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 rect = NSMakeRect(0, y, size.width, size.height - y - spaceForIcon - 155 rect = NSMakeRect(0, y, size.width, size.height - y - spaceForIcon -
156 kBubbleControlVerticalSpacing * 2); 156 kBubbleControlVerticalSpacing * 2);
157 [instructionLabel_ setFrame:rect]; 157 [instructionLabel_ setFrame:rect];
158 y = size.height - spaceForIcon - kBubbleControlVerticalSpacing; 158 y = size.height - spaceForIcon - kBubbleControlVerticalSpacing;
159 } 159 }
160 160
161 if (![iconImage_ isHidden]) { 161 if (![iconImage_ isHidden]) {
162 rect.size = [[iconImage_ image] size]; 162 rect.size = [[iconImage_ image] size];
163 // In warm-up mode only the icon gets displayed so center it vertically. 163 // In warm-up mode only the icon gets displayed so center it vertically.
164 if (displayMode_ == SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP) 164 if (displayMode_ == SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP)
165 y = (size.height - rect.size.height) / 2; 165 y = (size.height - rect.size.height) / 2;
166 rect.origin.x = (size.width - NSWidth(rect)) / 2; 166 rect.origin.x = (size.width - NSWidth(rect)) / 2;
167 rect.origin.y = y; 167 rect.origin.y = y;
168 [iconImage_ setFrame:rect]; 168 [iconImage_ setFrame:rect];
169 } 169 }
170 } 170 }
171 171
172 - (void)updateLayout:(SpeechInputBubbleBase::DisplayMode)mode 172 - (void)updateLayout:(SpeechRecognitionBubbleBase::DisplayMode)mode
173 messageText:(const string16&)messageText 173 messageText:(const string16&)messageText
174 iconImage:(NSImage*)iconImage { 174 iconImage:(NSImage*)iconImage {
175 // The very first time this method is called, the child views would still be 175 // The very first time this method is called, the child views would still be
176 // uninitialized and null. So we invoke [self window] first and that sets up 176 // uninitialized and null. So we invoke [self window] first and that sets up
177 // the child views properly so we can do the layout calculations below. 177 // the child views properly so we can do the layout calculations below.
178 NSWindow* window = [self window]; 178 NSWindow* window = [self window];
179 displayMode_ = mode; 179 displayMode_ = mode;
180 BOOL is_message = (mode == SpeechInputBubbleBase::DISPLAY_MODE_MESSAGE); 180 BOOL is_message = (mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_MESSAGE);
181 BOOL is_recording = (mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING); 181 BOOL is_recording =
182 BOOL is_warm_up = (mode == SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP); 182 (mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_RECORDING);
183 BOOL is_warm_up = (mode == SpeechRecognitionBubbleBase::DISPLAY_MODE_WARM_UP);
183 [iconImage_ setHidden:is_message]; 184 [iconImage_ setHidden:is_message];
184 [tryAgainButton_ setHidden:!is_message]; 185 [tryAgainButton_ setHidden:!is_message];
185 [micSettingsButton_ setHidden:!is_message]; 186 [micSettingsButton_ setHidden:!is_message];
186 [instructionLabel_ setHidden:!is_message && !is_recording]; 187 [instructionLabel_ setHidden:!is_message && !is_recording];
187 [cancelButton_ setHidden:is_warm_up]; 188 [cancelButton_ setHidden:is_warm_up];
188 189
189 // Get the right set of controls to be visible. 190 // Get the right set of controls to be visible.
190 if (is_message) { 191 if (is_message) {
191 [instructionLabel_ setStringValue:base::SysUTF16ToNSString(messageText)]; 192 [instructionLabel_ setStringValue:base::SysUTF16ToNSString(messageText)];
192 } else { 193 } else {
(...skipping 23 matching lines...) Expand all
216 } 217 }
217 218
218 - (void)hide { 219 - (void)hide {
219 [[self window] orderOut:nil]; 220 [[self window] orderOut:nil];
220 } 221 }
221 222
222 - (void)setImage:(NSImage*)image { 223 - (void)setImage:(NSImage*)image {
223 [iconImage_ setImage:image]; 224 [iconImage_ setImage:image];
224 } 225 }
225 226
226 @end // implementation SpeechInputWindowController 227 @end // implementation SpeechRecognitionWindowController
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/speech_recognition_window_controller.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698