| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 views::View* target_; | 149 views::View* target_; |
| 150 | 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver); | 151 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver); |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 //////////////////////////////////////////////////////////////////////////////// | 154 //////////////////////////////////////////////////////////////////////////////// |
| 155 // AppListView: | 155 // AppListView: |
| 156 | 156 |
| 157 AppListView::AppListView(AppListViewDelegate* delegate) | 157 AppListView::AppListView(AppListViewDelegate* delegate) |
| 158 : delegate_(delegate), | 158 : delegate_(delegate), |
| 159 app_list_main_view_(NULL), | 159 app_list_main_view_(nullptr), |
| 160 search_box_view_(NULL), | 160 speech_view_(nullptr), |
| 161 speech_view_(NULL), | 161 search_box_widget_(nullptr), |
| 162 overlay_view_(NULL), | 162 search_box_view_(nullptr), |
| 163 overlay_view_(nullptr), |
| 163 animation_observer_(new HideViewAnimationObserver()) { | 164 animation_observer_(new HideViewAnimationObserver()) { |
| 164 CHECK(delegate); | 165 CHECK(delegate); |
| 165 | 166 |
| 166 delegate_->AddObserver(this); | 167 delegate_->AddObserver(this); |
| 167 delegate_->GetSpeechUI()->AddObserver(this); | 168 delegate_->GetSpeechUI()->AddObserver(this); |
| 168 } | 169 } |
| 169 | 170 |
| 170 AppListView::~AppListView() { | 171 AppListView::~AppListView() { |
| 171 delegate_->GetSpeechUI()->RemoveObserver(this); | 172 delegate_->GetSpeechUI()->RemoveObserver(this); |
| 172 delegate_->RemoveObserver(this); | 173 delegate_->RemoveObserver(this); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 212 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 212 params.parent = parent; | 213 params.parent = parent; |
| 213 params.delegate = this; | 214 params.delegate = this; |
| 214 widget->Init(params); | 215 widget->Init(params); |
| 215 widget->SetBounds(bounds); | 216 widget->SetBounds(bounds); |
| 216 // This needs to be set *after* Widget::Init() because BubbleDelegateView sets | 217 // This needs to be set *after* Widget::Init() because BubbleDelegateView sets |
| 217 // its own background at OnNativeThemeChanged(), which is called in | 218 // its own background at OnNativeThemeChanged(), which is called in |
| 218 // View::AddChildView() which is called at Widget::SetContentsView() to build | 219 // View::AddChildView() which is called at Widget::SetContentsView() to build |
| 219 // the views hierarchy in the widget. | 220 // the views hierarchy in the widget. |
| 220 set_background(new AppListBackground(0, app_list_main_view_)); | 221 set_background(new AppListBackground(0, app_list_main_view_)); |
| 222 |
| 223 InitChildWidgets(); |
| 221 } | 224 } |
| 222 | 225 |
| 223 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { | 226 void AppListView::SetBubbleArrow(views::BubbleBorder::Arrow arrow) { |
| 224 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); | 227 GetBubbleFrameView()->bubble_border()->set_arrow(arrow); |
| 225 SizeToContents(); // Recalcuates with new border. | 228 SizeToContents(); // Recalcuates with new border. |
| 226 GetBubbleFrameView()->SchedulePaint(); | 229 GetBubbleFrameView()->SchedulePaint(); |
| 227 } | 230 } |
| 228 | 231 |
| 229 void AppListView::SetAnchorPoint(const gfx::Point& anchor_point) { | 232 void AppListView::SetAnchorPoint(const gfx::Point& anchor_point) { |
| 230 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | 233 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 ->pagination_model(); | 350 ->pagination_model(); |
| 348 } | 351 } |
| 349 | 352 |
| 350 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { | 353 void AppListView::InitContents(gfx::NativeView parent, int initial_apps_page) { |
| 351 app_list_main_view_ = new AppListMainView(delegate_); | 354 app_list_main_view_ = new AppListMainView(delegate_); |
| 352 AddChildView(app_list_main_view_); | 355 AddChildView(app_list_main_view_); |
| 353 app_list_main_view_->SetPaintToLayer(true); | 356 app_list_main_view_->SetPaintToLayer(true); |
| 354 app_list_main_view_->SetFillsBoundsOpaquely(false); | 357 app_list_main_view_->SetFillsBoundsOpaquely(false); |
| 355 app_list_main_view_->layer()->SetMasksToBounds(true); | 358 app_list_main_view_->layer()->SetMasksToBounds(true); |
| 356 | 359 |
| 360 // This will be added to the |search_box_widget_| after the app list widget is |
| 361 // initialized. |
| 357 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); | 362 search_box_view_ = new SearchBoxView(app_list_main_view_, delegate_); |
| 358 search_box_view_->SetPaintToLayer(true); | 363 search_box_view_->SetPaintToLayer(true); |
| 359 search_box_view_->SetFillsBoundsOpaquely(false); | 364 search_box_view_->SetFillsBoundsOpaquely(false); |
| 360 search_box_view_->layer()->SetMasksToBounds(true); | 365 search_box_view_->layer()->SetMasksToBounds(true); |
| 361 AddChildView(search_box_view_); | |
| 362 | 366 |
| 363 app_list_main_view_->Init(parent, initial_apps_page, search_box_view_); | 367 app_list_main_view_->Init(parent, initial_apps_page, search_box_view_); |
| 364 | 368 |
| 365 // Speech recognition is available only when the start page exists. | 369 // Speech recognition is available only when the start page exists. |
| 366 if (delegate_ && delegate_->IsSpeechRecognitionEnabled()) { | 370 if (delegate_ && delegate_->IsSpeechRecognitionEnabled()) { |
| 367 speech_view_ = new SpeechView(delegate_); | 371 speech_view_ = new SpeechView(delegate_); |
| 368 speech_view_->SetVisible(false); | 372 speech_view_->SetVisible(false); |
| 369 speech_view_->SetPaintToLayer(true); | 373 speech_view_->SetPaintToLayer(true); |
| 370 speech_view_->SetFillsBoundsOpaquely(false); | 374 speech_view_->SetFillsBoundsOpaquely(false); |
| 371 speech_view_->layer()->SetOpacity(0.0f); | 375 speech_view_->layer()->SetOpacity(0.0f); |
| 372 AddChildView(speech_view_); | 376 AddChildView(speech_view_); |
| 373 } | 377 } |
| 374 | 378 |
| 375 OnProfilesChanged(); | 379 OnProfilesChanged(); |
| 376 } | 380 } |
| 377 | 381 |
| 382 void AppListView::InitChildWidgets() { |
| 383 DCHECK(search_box_view_); |
| 384 |
| 385 app_list_main_view_->InitWidgets(); |
| 386 |
| 387 // Create the search box widget. |
| 388 views::Widget::InitParams search_box_widget_params( |
| 389 views::Widget::InitParams::TYPE_CONTROL); |
| 390 search_box_widget_params.parent = GetWidget()->GetNativeView(); |
| 391 search_box_widget_params.opacity = |
| 392 views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 393 |
| 394 // Create a widget for the SearchBoxView to live in. This allows the |
| 395 // SearchBoxView to be on top of the custom launcher page's WebContents |
| 396 // (otherwise the search box events will be captured by the WebContents). |
| 397 search_box_widget_ = new views::Widget; |
| 398 search_box_widget_->Init(search_box_widget_params); |
| 399 search_box_widget_->SetContentsView(search_box_view_); |
| 400 |
| 401 Layout(); |
| 402 } |
| 403 |
| 378 void AppListView::InitAsBubbleInternal(gfx::NativeView parent, | 404 void AppListView::InitAsBubbleInternal(gfx::NativeView parent, |
| 379 int initial_apps_page, | 405 int initial_apps_page, |
| 380 views::BubbleBorder::Arrow arrow, | 406 views::BubbleBorder::Arrow arrow, |
| 381 bool border_accepts_events, | 407 bool border_accepts_events, |
| 382 const gfx::Vector2d& anchor_offset) { | 408 const gfx::Vector2d& anchor_offset) { |
| 383 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 409 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 384 tracked_objects::ScopedTracker tracking_profile1( | 410 tracked_objects::ScopedTracker tracking_profile1( |
| 385 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 411 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 386 "431326 AppListView::InitAsBubbleInternal1")); | 412 "431326 AppListView::InitAsBubbleInternal1")); |
| 387 | 413 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 405 kArrowOffset - anchor_offset.x())); | 431 kArrowOffset - anchor_offset.x())); |
| 406 set_border_accepts_events(border_accepts_events); | 432 set_border_accepts_events(border_accepts_events); |
| 407 set_shadow(SupportsShadow() ? views::BubbleBorder::BIG_SHADOW | 433 set_shadow(SupportsShadow() ? views::BubbleBorder::BIG_SHADOW |
| 408 : views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER); | 434 : views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER); |
| 409 // This creates the app list widget. (Before this, child widgets cannot be | 435 // This creates the app list widget. (Before this, child widgets cannot be |
| 410 // created.) | 436 // created.) |
| 411 views::BubbleDelegateView::CreateBubble(this); | 437 views::BubbleDelegateView::CreateBubble(this); |
| 412 SetBubbleArrow(arrow); | 438 SetBubbleArrow(arrow); |
| 413 | 439 |
| 414 // We can now create the internal widgets. | 440 // We can now create the internal widgets. |
| 415 app_list_main_view_->InitWidgets(); | 441 InitChildWidgets(); |
| 416 | 442 |
| 417 #if defined(USE_AURA) | 443 #if defined(USE_AURA) |
| 418 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 444 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 419 tracked_objects::ScopedTracker tracking_profile3( | 445 tracked_objects::ScopedTracker tracking_profile3( |
| 420 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 446 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 421 "431326 AppListView::InitAsBubbleInternal3")); | 447 "431326 AppListView::InitAsBubbleInternal3")); |
| 422 | 448 |
| 423 aura::Window* window = GetWidget()->GetNativeWindow(); | 449 aura::Window* window = GetWidget()->GetNativeWindow(); |
| 424 window->layer()->SetMasksToBounds(true); | 450 window->layer()->SetMasksToBounds(true); |
| 425 GetBubbleFrameView()->set_background(new AppListBackground( | 451 GetBubbleFrameView()->set_background(new AppListBackground( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 | 582 |
| 557 app_list_main_view_->SetBoundsRect(centered_bounds); | 583 app_list_main_view_->SetBoundsRect(centered_bounds); |
| 558 | 584 |
| 559 // GetDefaultSearchBoxBounds() returns the bounds in |contents_view|'s | 585 // GetDefaultSearchBoxBounds() returns the bounds in |contents_view|'s |
| 560 // coordinate, therefore convert it to this coordinate. | 586 // coordinate, therefore convert it to this coordinate. |
| 561 ContentsView* contents_view = app_list_main_view_->contents_view(); | 587 ContentsView* contents_view = app_list_main_view_->contents_view(); |
| 562 // TODO(mgiuca): Position the search box in the center of the page, when | 588 // TODO(mgiuca): Position the search box in the center of the page, when |
| 563 // in STATE_START. | 589 // in STATE_START. |
| 564 gfx::RectF search_box_bounds = contents_view->GetDefaultSearchBoxBounds(); | 590 gfx::RectF search_box_bounds = contents_view->GetDefaultSearchBoxBounds(); |
| 565 ConvertRectToTarget(contents_view, this, &search_box_bounds); | 591 ConvertRectToTarget(contents_view, this, &search_box_bounds); |
| 566 search_box_view_->SetBoundsRect(gfx::ToNearestRect(search_box_bounds)); | 592 if (search_box_widget_) { |
| 593 search_box_widget_->SetBounds( |
| 594 ConvertRectToWidget(gfx::ToNearestRect(search_box_bounds))); |
| 595 } |
| 567 | 596 |
| 568 if (speech_view_) { | 597 if (speech_view_) { |
| 569 gfx::Rect speech_bounds = centered_bounds; | 598 gfx::Rect speech_bounds = centered_bounds; |
| 570 int preferred_height = speech_view_->GetPreferredSize().height(); | 599 int preferred_height = speech_view_->GetPreferredSize().height(); |
| 571 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); | 600 speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); |
| 572 speech_bounds.set_height(std::min(speech_bounds.height(), | 601 speech_bounds.set_height(std::min(speech_bounds.height(), |
| 573 preferred_height)); | 602 preferred_height)); |
| 574 speech_bounds.Inset(-speech_view_->GetInsets()); | 603 speech_bounds.Inset(-speech_view_->GetInsets()); |
| 575 speech_view_->SetBoundsRect(speech_bounds); | 604 speech_view_->SetBoundsRect(speech_bounds); |
| 576 } | 605 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 speech_view_->layer()->SetTransform(speech_transform); | 684 speech_view_->layer()->SetTransform(speech_transform); |
| 656 } | 685 } |
| 657 | 686 |
| 658 if (will_appear) | 687 if (will_appear) |
| 659 speech_view_->SetVisible(true); | 688 speech_view_->SetVisible(true); |
| 660 else | 689 else |
| 661 app_list_main_view_->SetVisible(true); | 690 app_list_main_view_->SetVisible(true); |
| 662 } | 691 } |
| 663 | 692 |
| 664 } // namespace app_list | 693 } // namespace app_list |
| OLD | NEW |