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

Side by Side Diff: chrome/browser/speech/speech_input_bubble_views.cc

Issue 7057014: Variety of tweaks to View API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/speech/speech_input_bubble.h" 5 #include "chrome/browser/speech/speech_input_bubble.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 try_again_->SetVisible(is_message); 125 try_again_->SetVisible(is_message);
126 cancel_->SetVisible(mode != SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP); 126 cancel_->SetVisible(mode != SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP);
127 heading_->SetVisible(mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING); 127 heading_->SetVisible(mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING);
128 128
129 if (is_message) { 129 if (is_message) {
130 message_->SetText(UTF16ToWideHack(message_text)); 130 message_->SetText(UTF16ToWideHack(message_text));
131 } else { 131 } else {
132 SetImage(image); 132 SetImage(image);
133 } 133 }
134 134
135 if (icon_->IsVisible()) 135 if (icon_->visible())
136 icon_->ResetImageSize(); 136 icon_->ResetImageSize();
137 137
138 // When moving from warming up to recording state, the size of the content 138 // When moving from warming up to recording state, the size of the content
139 // stays the same. So we wouldn't get a resize/layout call from the view 139 // stays the same. So we wouldn't get a resize/layout call from the view
140 // system and we do it ourselves. 140 // system and we do it ourselves.
141 if (GetPreferredSize() == size()) // |size()| here is the current size. 141 if (GetPreferredSize() == size()) // |size()| here is the current size.
142 Layout(); 142 Layout();
143 } 143 }
144 144
145 void ContentView::SetImage(const SkBitmap& image) { 145 void ContentView::SetImage(const SkBitmap& image) {
(...skipping 12 matching lines...) Expand all
158 } 158 }
159 159
160 void ContentView::LinkClicked(views::Link* source, int event_flags) { 160 void ContentView::LinkClicked(views::Link* source, int event_flags) {
161 DCHECK_EQ(source, mic_settings_); 161 DCHECK_EQ(source, mic_settings_);
162 AudioManager::GetAudioManager()->ShowAudioInputSettings(); 162 AudioManager::GetAudioManager()->ShowAudioInputSettings();
163 } 163 }
164 164
165 gfx::Size ContentView::GetPreferredSize() { 165 gfx::Size ContentView::GetPreferredSize() {
166 int width = heading_->GetPreferredSize().width(); 166 int width = heading_->GetPreferredSize().width();
167 int control_width = cancel_->GetPreferredSize().width(); 167 int control_width = cancel_->GetPreferredSize().width();
168 if (try_again_->IsVisible()) { 168 if (try_again_->visible()) {
169 control_width += try_again_->GetPreferredSize().width() + 169 control_width += try_again_->GetPreferredSize().width() +
170 views::kRelatedButtonHSpacing; 170 views::kRelatedButtonHSpacing;
171 } 171 }
172 width = std::max(width, control_width); 172 width = std::max(width, control_width);
173 control_width = std::max(icon_->GetPreferredSize().width(), 173 control_width = std::max(icon_->GetPreferredSize().width(),
174 kIconLayoutMinWidth); 174 kIconLayoutMinWidth);
175 width = std::max(width, control_width); 175 width = std::max(width, control_width);
176 if (mic_settings_->IsVisible()) { 176 if (mic_settings_->visible()) {
177 control_width = mic_settings_->GetPreferredSize().width(); 177 control_width = mic_settings_->GetPreferredSize().width();
178 width = std::max(width, control_width); 178 width = std::max(width, control_width);
179 } 179 }
180 180
181 int height = cancel_->GetPreferredSize().height(); 181 int height = cancel_->GetPreferredSize().height();
182 if (message_->IsVisible()) { 182 if (message_->visible()) {
183 height += message_->GetHeightForWidth(width) + 183 height += message_->GetHeightForWidth(width) +
184 views::kLabelToControlVerticalSpacing; 184 views::kLabelToControlVerticalSpacing;
185 } 185 }
186 if (heading_->IsVisible()) 186 if (heading_->visible())
187 height += heading_->GetPreferredSize().height(); 187 height += heading_->GetPreferredSize().height();
188 if (icon_->IsVisible()) 188 if (icon_->visible())
189 height += icon_->GetImage().height(); 189 height += icon_->GetImage().height();
190 if (mic_settings_->IsVisible()) 190 if (mic_settings_->visible())
191 height += mic_settings_->GetPreferredSize().height(); 191 height += mic_settings_->GetPreferredSize().height();
192 width += kBubbleHorizMargin * 2; 192 width += kBubbleHorizMargin * 2;
193 height += kBubbleVertMargin * 2; 193 height += kBubbleVertMargin * 2;
194 194
195 return gfx::Size(width, height); 195 return gfx::Size(width, height);
196 } 196 }
197 197
198 void ContentView::Layout() { 198 void ContentView::Layout() {
199 int x = kBubbleHorizMargin; 199 int x = kBubbleHorizMargin;
200 int y = kBubbleVertMargin; 200 int y = kBubbleVertMargin;
201 int available_width = width() - kBubbleHorizMargin * 2; 201 int available_width = width() - kBubbleHorizMargin * 2;
202 int available_height = height() - kBubbleVertMargin * 2; 202 int available_height = height() - kBubbleVertMargin * 2;
203 203
204 if (message_->IsVisible()) { 204 if (message_->visible()) {
205 DCHECK(try_again_->IsVisible()); 205 DCHECK(try_again_->visible());
206 206
207 int control_height = try_again_->GetPreferredSize().height(); 207 int control_height = try_again_->GetPreferredSize().height();
208 int try_again_width = try_again_->GetPreferredSize().width(); 208 int try_again_width = try_again_->GetPreferredSize().width();
209 int cancel_width = cancel_->GetPreferredSize().width(); 209 int cancel_width = cancel_->GetPreferredSize().width();
210 y += available_height - control_height; 210 y += available_height - control_height;
211 x += (available_width - cancel_width - try_again_width - 211 x += (available_width - cancel_width - try_again_width -
212 views::kRelatedButtonHSpacing) / 2; 212 views::kRelatedButtonHSpacing) / 2;
213 try_again_->SetBounds(x, y, try_again_width, control_height); 213 try_again_->SetBounds(x, y, try_again_width, control_height);
214 cancel_->SetBounds(x + try_again_width + views::kRelatedButtonHSpacing, y, 214 cancel_->SetBounds(x + try_again_width + views::kRelatedButtonHSpacing, y,
215 cancel_width, control_height); 215 cancel_width, control_height);
216 216
217 control_height = message_->GetHeightForWidth(available_width); 217 control_height = message_->GetHeightForWidth(available_width);
218 message_->SetBounds(kBubbleHorizMargin, kBubbleVertMargin, 218 message_->SetBounds(kBubbleHorizMargin, kBubbleVertMargin,
219 available_width, control_height); 219 available_width, control_height);
220 y = kBubbleVertMargin + control_height; 220 y = kBubbleVertMargin + control_height;
221 221
222 control_height = mic_settings_->GetPreferredSize().height(); 222 control_height = mic_settings_->GetPreferredSize().height();
223 mic_settings_->SetBounds(kBubbleHorizMargin, y, available_width, 223 mic_settings_->SetBounds(kBubbleHorizMargin, y, available_width,
224 control_height); 224 control_height);
225 } else { 225 } else {
226 DCHECK(icon_->IsVisible()); 226 DCHECK(icon_->visible());
227 227
228 int control_height = icon_->GetImage().height(); 228 int control_height = icon_->GetImage().height();
229 if (display_mode_ == SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP) 229 if (display_mode_ == SpeechInputBubbleBase::DISPLAY_MODE_WARM_UP)
230 y = (available_height - control_height) / 2; 230 y = (available_height - control_height) / 2;
231 icon_->SetBounds(x, y, available_width, control_height); 231 icon_->SetBounds(x, y, available_width, control_height);
232 y += control_height; 232 y += control_height;
233 233
234 if (heading_->IsVisible()) { 234 if (heading_->visible()) {
235 control_height = heading_->GetPreferredSize().height(); 235 control_height = heading_->GetPreferredSize().height();
236 heading_->SetBounds(x, y, available_width, control_height); 236 heading_->SetBounds(x, y, available_width, control_height);
237 y += control_height; 237 y += control_height;
238 } 238 }
239 239
240 if (cancel_->IsVisible()) { 240 if (cancel_->visible()) {
241 control_height = cancel_->GetPreferredSize().height(); 241 control_height = cancel_->GetPreferredSize().height();
242 int width = cancel_->GetPreferredSize().width(); 242 int width = cancel_->GetPreferredSize().width();
243 cancel_->SetBounds(x + (available_width - width) / 2, y, width, 243 cancel_->SetBounds(x + (available_width - width) / 2, y, width,
244 control_height); 244 control_height);
245 } 245 }
246 } 246 }
247 } 247 }
248 248
249 // Implementation of SpeechInputBubble. 249 // Implementation of SpeechInputBubble.
250 class SpeechInputBubbleImpl 250 class SpeechInputBubbleImpl
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 371 }
372 372
373 } // namespace 373 } // namespace
374 374
375 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( 375 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble(
376 TabContents* tab_contents, 376 TabContents* tab_contents,
377 SpeechInputBubble::Delegate* delegate, 377 SpeechInputBubble::Delegate* delegate,
378 const gfx::Rect& element_rect) { 378 const gfx::Rect& element_rect) {
379 return new SpeechInputBubbleImpl(tab_contents, delegate, element_rect); 379 return new SpeechInputBubbleImpl(tab_contents, delegate, element_rect);
380 } 380 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider_views.cc ('k') | chrome/browser/ui/panels/panel_browser_frame_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698