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

Side by Side Diff: ui/app_list/views/app_list_view.cc

Issue 105773004: Introduces the speech recognition UI to app_list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: start_page existence Created 7 years 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) 2012 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 #include "ui/app_list/views/app_list_view.h" 5 #include "ui/app_list/views/app_list_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "ui/app_list/app_list_constants.h" 9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/app_list_model.h" 10 #include "ui/app_list/app_list_model.h"
11 #include "ui/app_list/app_list_view_delegate.h" 11 #include "ui/app_list/app_list_view_delegate.h"
12 #include "ui/app_list/pagination_model.h" 12 #include "ui/app_list/pagination_model.h"
13 #include "ui/app_list/signin_delegate.h" 13 #include "ui/app_list/signin_delegate.h"
14 #include "ui/app_list/views/app_list_background.h" 14 #include "ui/app_list/views/app_list_background.h"
15 #include "ui/app_list/views/app_list_main_view.h" 15 #include "ui/app_list/views/app_list_main_view.h"
16 #include "ui/app_list/views/search_box_view.h" 16 #include "ui/app_list/views/search_box_view.h"
17 #include "ui/app_list/views/signin_view.h" 17 #include "ui/app_list/views/signin_view.h"
18 #include "ui/app_list/views/speech_view.h"
18 #include "ui/base/ui_base_switches.h" 19 #include "ui/base/ui_base_switches.h"
20 #include "ui/compositor/layer.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/gfx/image/image_skia.h" 22 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/insets.h" 23 #include "ui/gfx/insets.h"
21 #include "ui/gfx/path.h" 24 #include "ui/gfx/path.h"
22 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
23 #include "ui/views/bubble/bubble_frame_view.h" 26 #include "ui/views/bubble/bubble_frame_view.h"
24 #include "ui/views/controls/textfield/textfield.h" 27 #include "ui/views/controls/textfield/textfield.h"
25 #include "ui/views/layout/fill_layout.h" 28 #include "ui/views/layout/fill_layout.h"
26 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
27 30
28 #if defined(USE_AURA) 31 #if defined(USE_AURA)
29 #include "ui/aura/window.h" 32 #include "ui/aura/window.h"
30 #include "ui/aura/root_window.h" 33 #include "ui/aura/root_window.h"
31 #if defined(OS_WIN) 34 #if defined(OS_WIN)
32 #include "ui/base/win/shell.h" 35 #include "ui/base/win/shell.h"
33 #endif 36 #endif
34 #if !defined(OS_CHROMEOS) 37 #if !defined(OS_CHROMEOS)
35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 38 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
36 #endif 39 #endif
37 #endif // defined(USE_AURA) 40 #endif // defined(USE_AURA)
38 41
39 namespace app_list { 42 namespace app_list {
40 43
41 namespace { 44 namespace {
42 45
43 void (*g_next_paint_callback)(); 46 void (*g_next_paint_callback)();
44 47
48 // The margin from the edge to the speech UI.
49 const int kSpeechUIMargin = 12;
50
51 // The vertical position for the appearing animation of the speech UI.
52 const float kSpeechUIApearingPosition =12;
53
45 // The distance between the arrow tip and edge of the anchor view. 54 // The distance between the arrow tip and edge of the anchor view.
46 const int kArrowOffset = 10; 55 const int kArrowOffset = 10;
47 56
48 #if defined(OS_LINUX) 57 #if defined(OS_LINUX)
49 // The WM_CLASS name for the app launcher window on Linux. 58 // The WM_CLASS name for the app launcher window on Linux.
50 const char* kAppListWMClass = "chrome_app_list"; 59 const char* kAppListWMClass = "chrome_app_list";
51 #endif 60 #endif
52 61
53 // Determines whether the current environment supports shadows bubble borders. 62 // Determines whether the current environment supports shadows bubble borders.
54 bool SupportsShadow() { 63 bool SupportsShadow() {
(...skipping 12 matching lines...) Expand all
67 } 76 }
68 77
69 } // namespace 78 } // namespace
70 79
71 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
72 // AppListView: 81 // AppListView:
73 82
74 AppListView::AppListView(AppListViewDelegate* delegate) 83 AppListView::AppListView(AppListViewDelegate* delegate)
75 : delegate_(delegate), 84 : delegate_(delegate),
76 app_list_main_view_(NULL), 85 app_list_main_view_(NULL),
77 signin_view_(NULL) { 86 signin_view_(NULL),
87 speech_view_(NULL) {
78 CHECK(delegate); 88 CHECK(delegate);
79 delegate_->GetModel()->AddObserver(this); 89 delegate_->GetModel()->AddObserver(this);
90 delegate_->GetModel()->speech_ui()->AddObserver(this);
80 } 91 }
81 92
82 AppListView::~AppListView() { 93 AppListView::~AppListView() {
94 delegate_->GetModel()->speech_ui()->RemoveObserver(this);
83 delegate_->GetModel()->RemoveObserver(this); 95 delegate_->GetModel()->RemoveObserver(this);
84 // Remove child views first to ensure no remaining dependencies on delegate_. 96 // Remove child views first to ensure no remaining dependencies on delegate_.
85 RemoveAllChildViews(true); 97 RemoveAllChildViews(true);
86 } 98 }
87 99
88 void AppListView::InitAsBubbleAttachedToAnchor( 100 void AppListView::InitAsBubbleAttachedToAnchor(
89 gfx::NativeView parent, 101 gfx::NativeView parent,
90 PaginationModel* pagination_model, 102 PaginationModel* pagination_model,
91 views::View* anchor, 103 views::View* anchor,
92 const gfx::Vector2d& anchor_offset, 104 const gfx::Vector2d& anchor_offset,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 app_list_main_view_->SetPaintToLayer(true); 218 app_list_main_view_->SetPaintToLayer(true);
207 app_list_main_view_->SetFillsBoundsOpaquely(false); 219 app_list_main_view_->SetFillsBoundsOpaquely(false);
208 app_list_main_view_->layer()->SetMasksToBounds(true); 220 app_list_main_view_->layer()->SetMasksToBounds(true);
209 #endif 221 #endif
210 222
211 signin_view_ = 223 signin_view_ =
212 new SigninView(delegate_->GetSigninDelegate(), 224 new SigninView(delegate_->GetSigninDelegate(),
213 app_list_main_view_->GetPreferredSize().width()); 225 app_list_main_view_->GetPreferredSize().width());
214 AddChildView(signin_view_); 226 AddChildView(signin_view_);
215 227
228 // Speech recognition is available only when the start page exists.
229 if (delegate_ && delegate_->GetStartPageContents()) {
230 speech_view_ = new SpeechView(delegate_.get());
231 speech_view_->SetVisible(false);
232 #if defined(USE_AURA)
233 speech_view_->SetPaintToLayer(true);
234 speech_view_->SetFillsBoundsOpaquely(false);
235 #endif
236 AddChildView(speech_view_);
237 }
238
216 OnSigninStatusChanged(); 239 OnSigninStatusChanged();
217 set_color(kContentsBackgroundColor); 240 set_color(kContentsBackgroundColor);
218 set_margins(gfx::Insets()); 241 set_margins(gfx::Insets());
219 set_move_with_anchor(true); 242 set_move_with_anchor(true);
220 set_parent_window(parent); 243 set_parent_window(parent);
221 set_close_on_deactivate(false); 244 set_close_on_deactivate(false);
222 set_close_on_esc(false); 245 set_close_on_esc(false);
223 set_anchor_view_insets(gfx::Insets(kArrowOffset + anchor_offset.y(), 246 set_anchor_view_insets(gfx::Insets(kArrowOffset + anchor_offset.y(),
224 kArrowOffset + anchor_offset.x(), 247 kArrowOffset + anchor_offset.x(),
225 kArrowOffset - anchor_offset.y(), 248 kArrowOffset - anchor_offset.y(),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 return true; 320 return true;
298 } 321 }
299 322
300 return false; 323 return false;
301 } 324 }
302 325
303 void AppListView::Layout() { 326 void AppListView::Layout() {
304 const gfx::Rect contents_bounds = GetContentsBounds(); 327 const gfx::Rect contents_bounds = GetContentsBounds();
305 app_list_main_view_->SetBoundsRect(contents_bounds); 328 app_list_main_view_->SetBoundsRect(contents_bounds);
306 signin_view_->SetBoundsRect(contents_bounds); 329 signin_view_->SetBoundsRect(contents_bounds);
330
331 if (speech_view_) {
332 gfx::Rect speech_bounds = contents_bounds;
333 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin);
334 speech_bounds.set_height(std::min(speech_bounds.height(),
335 SpeechView::kMaxHeight));
336 speech_bounds.Inset(-speech_view_->GetInsets());
337 speech_view_->SetBoundsRect(speech_bounds);
338 }
307 } 339 }
308 340
309 void AppListView::OnWidgetDestroying(views::Widget* widget) { 341 void AppListView::OnWidgetDestroying(views::Widget* widget) {
310 BubbleDelegateView::OnWidgetDestroying(widget); 342 BubbleDelegateView::OnWidgetDestroying(widget);
311 if (delegate_ && widget == GetWidget()) 343 if (delegate_ && widget == GetWidget())
312 delegate_->ViewClosing(); 344 delegate_->ViewClosing();
313 } 345 }
314 346
315 void AppListView::OnWidgetActivationChanged(views::Widget* widget, 347 void AppListView::OnWidgetActivationChanged(views::Widget* widget,
316 bool active) { 348 bool active) {
(...skipping 18 matching lines...) Expand all
335 367
336 // Whether we need to signin or not may have changed since last time we were 368 // Whether we need to signin or not may have changed since last time we were
337 // shown. 369 // shown.
338 Layout(); 370 Layout();
339 } 371 }
340 372
341 void AppListView::OnAppListModelSigninStatusChanged() { 373 void AppListView::OnAppListModelSigninStatusChanged() {
342 OnSigninStatusChanged(); 374 OnSigninStatusChanged();
343 } 375 }
344 376
377 void AppListView::OnSpeechRecognitionStateChanged(
378 SpeechRecognitionState new_state) {
379 DCHECK(!signin_view_->visible());
380
381 bool recognizing = new_state != SPEECH_RECOGNITION_NOT_STARTED;
382 // No change for this class.
383 if (speech_view_->visible() == recognizing)
384 return;
385
386 if (recognizing)
387 speech_view_->Reset();
388
389 #if defined(USE_AURA)
390 {
391 ui::ScopedLayerAnimationSettings main_settings(
392 app_list_main_view_->layer()->GetAnimator());
393 app_list_main_view_->layer()->SetOpacity(recognizing ? 0.0f : 1.0f);
394 }
395
396 gfx::Transform speech_transform;
397 speech_transform.Translate(
398 0, SkFloatToMScalar(kSpeechUIApearingPosition));
399 if (recognizing)
400 speech_view_->layer()->SetTransform(speech_transform);
401
402 {
403 ui::ScopedLayerAnimationSettings speech_settings(
404 speech_view_->layer()->GetAnimator());
405 speech_view_->layer()->SetOpacity(recognizing ? 1.0f : 0.0f);
406 if (recognizing)
407 speech_view_->layer()->SetTransform(gfx::Transform());
408 else
409 speech_view_->layer()->SetTransform(speech_transform);
410 }
411 #endif
412
413 speech_view_->SetVisible(recognizing);
414 app_list_main_view_->SetVisible(!recognizing);
xiyuan 2013/12/05 22:06:30 Think we should call SetVisible of both views when
Jun Mukai 2013/12/06 00:31:10 Didn't notice that, thanks for pointing. Introduce
415
416 // Needs to schedule paint of AppListView itself, to repaint the background.
417 SchedulePaint();
418 }
419
345 } // namespace app_list 420 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698