Chromium Code Reviews| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 const int corner_radius_; | 100 const int corner_radius_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(AppListOverlayBackground); | 102 DISALLOW_COPY_AND_ASSIGN(AppListOverlayBackground); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 } // namespace | 105 } // namespace |
| 106 | 106 |
| 107 // An animation observer to hide the view at the end of the animation. | 107 // An animation observer to hide a set of views at the end of the animation. |
| 108 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { | 108 class HideViewAnimationObserver : public ui::ImplicitAnimationObserver { |
| 109 public: | 109 public: |
| 110 HideViewAnimationObserver() | 110 HideViewAnimationObserver() : frame_(NULL) {} |
| 111 : frame_(NULL), | |
| 112 target_(NULL) { | |
| 113 } | |
| 114 | 111 |
| 115 virtual ~HideViewAnimationObserver() { | 112 virtual ~HideViewAnimationObserver() { |
| 116 if (target_) | 113 if (targets_.empty()) |
| 117 StopObservingImplicitAnimations(); | 114 StopObservingImplicitAnimations(); |
| 118 } | 115 } |
| 119 | 116 |
| 120 void SetTarget(views::View* target) { | 117 void AddTarget(views::View* target) { |
| 121 if (!target_) | 118 if (target) |
| 119 targets_.push_back(target); | |
| 120 | |
| 121 if (targets_.empty()) | |
| 122 StopObservingImplicitAnimations(); | 122 StopObservingImplicitAnimations(); |
| 123 target_ = target; | |
| 124 } | 123 } |
| 125 | 124 |
| 126 void set_frame(views::BubbleFrameView* frame) { frame_ = frame; } | 125 void set_frame(views::BubbleFrameView* frame) { frame_ = frame; } |
| 127 | 126 |
| 128 private: | 127 private: |
| 129 // Overridden from ui::ImplicitAnimationObserver: | 128 // Overridden from ui::ImplicitAnimationObserver: |
| 130 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | 129 virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
| 131 if (target_) { | 130 for (size_t i = 0; i < targets_.size(); i++) |
| 132 target_->SetVisible(false); | 131 targets_[i]->SetVisible(false); |
| 133 target_ = NULL; | |
| 134 | 132 |
| 135 // Should update the background by invoking SchedulePaint(). | 133 // Should update the background by invoking SchedulePaint(). |
| 134 if (!targets_.empty()) | |
| 136 frame_->SchedulePaint(); | 135 frame_->SchedulePaint(); |
| 137 } | 136 |
| 137 targets_.clear(); | |
| 138 } | 138 } |
| 139 | 139 |
| 140 views::BubbleFrameView* frame_; | 140 views::BubbleFrameView* frame_; |
| 141 views::View* target_; | 141 std::vector<views::View*> targets_; |
| 142 | 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver); | 143 DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 //////////////////////////////////////////////////////////////////////////////// | 146 //////////////////////////////////////////////////////////////////////////////// |
| 147 // AppListView: | 147 // AppListView: |
| 148 | 148 |
| 149 AppListView::AppListView(AppListViewDelegate* delegate) | 149 AppListView::AppListView(AppListViewDelegate* delegate) |
| 150 : delegate_(delegate), | 150 : delegate_(delegate), |
| 151 app_list_main_view_(NULL), | 151 app_list_main_view_(NULL), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 app_list_main_view_->Close(); | 214 app_list_main_view_->Close(); |
| 215 delegate_->Dismiss(); | 215 delegate_->Dismiss(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void AppListView::UpdateBounds() { | 218 void AppListView::UpdateBounds() { |
| 219 SizeToContents(); | 219 SizeToContents(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void AppListView::SetAppListOverlayVisible(bool visible) { | 222 void AppListView::SetAppListOverlayVisible(bool visible) { |
| 223 DCHECK(overlay_view_); | 223 DCHECK(overlay_view_); |
| 224 overlay_view_->SetVisible(visible); | 224 |
| 225 // Display the overlay immediately so we can begin the animation. | |
| 226 overlay_view_->SetVisible(true); | |
| 227 | |
| 228 ui::ScopedLayerAnimationSettings settings( | |
| 229 overlay_view_->layer()->GetAnimator()); | |
| 230 settings.SetTweenType(gfx::Tween::LINEAR); | |
| 231 | |
| 232 // If we're dismissing the overlay, hide the view at the end of the animation. | |
| 233 if (visible == false) { | |
|
calamity
2014/08/04 03:33:47
Use !x over 'x == false'.
sashab
2014/08/04 05:39:16
Done.
| |
| 234 animation_observer_->set_frame(GetBubbleFrameView()); | |
|
calamity
2014/08/04 03:33:47
Does the background need to repaint? If not, pass
sashab
2014/08/04 05:39:16
Done.
| |
| 235 animation_observer_->AddTarget(overlay_view_); | |
| 236 settings.AddObserver(animation_observer_.get()); | |
| 237 } | |
| 238 | |
| 239 const float kOverlayFadeInMilliseconds = 125; | |
| 240 settings.SetTransitionDuration( | |
| 241 base::TimeDelta::FromMilliseconds(kOverlayFadeInMilliseconds)); | |
| 242 | |
| 243 const float kOverlayOpacity = 0.75f; | |
| 244 overlay_view_->layer()->SetOpacity(visible ? kOverlayOpacity : 0.0f); | |
| 225 } | 245 } |
| 226 | 246 |
| 227 bool AppListView::ShouldCenterWindow() const { | 247 bool AppListView::ShouldCenterWindow() const { |
| 228 return delegate_->ShouldCenterWindow(); | 248 return delegate_->ShouldCenterWindow(); |
| 229 } | 249 } |
| 230 | 250 |
| 231 gfx::Size AppListView::GetPreferredSize() const { | 251 gfx::Size AppListView::GetPreferredSize() const { |
| 232 return app_list_main_view_->GetPreferredSize(); | 252 return app_list_main_view_->GetPreferredSize(); |
| 233 } | 253 } |
| 234 | 254 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 // to be shown independently in odd situations. Explicitly hide the bubble | 379 // to be shown independently in odd situations. Explicitly hide the bubble |
| 360 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the | 380 // widget to ensure that any WM_WINDOWPOSCHANGED messages triggered by the |
| 361 // window manager do not have the SWP_SHOWWINDOW flag set which would cause | 381 // window manager do not have the SWP_SHOWWINDOW flag set which would cause |
| 362 // the border to be shown. See http://crbug.com/231687 . | 382 // the border to be shown. See http://crbug.com/231687 . |
| 363 GetWidget()->Hide(); | 383 GetWidget()->Hide(); |
| 364 #endif | 384 #endif |
| 365 | 385 |
| 366 // To make the overlay view, construct a view with a white background, rather | 386 // To make the overlay view, construct a view with a white background, rather |
| 367 // than a white rectangle in it. This is because we need overlay_view_ to be | 387 // than a white rectangle in it. This is because we need overlay_view_ to be |
| 368 // drawn to its own layer (so it appears correctly in the foreground). | 388 // drawn to its own layer (so it appears correctly in the foreground). |
| 369 const float kOverlayOpacity = 0.75f; | |
| 370 overlay_view_ = new views::View(); | 389 overlay_view_ = new views::View(); |
| 371 overlay_view_->SetPaintToLayer(true); | 390 overlay_view_->SetPaintToLayer(true); |
| 372 overlay_view_->layer()->SetOpacity(kOverlayOpacity); | |
| 373 overlay_view_->SetBoundsRect(GetContentsBounds()); | 391 overlay_view_->SetBoundsRect(GetContentsBounds()); |
| 374 overlay_view_->SetVisible(false); | 392 overlay_view_->SetVisible(false); |
| 393 overlay_view_->layer()->SetOpacity(0.0f); | |
| 375 // On platforms that don't support a shadow, the rounded border of the app | 394 // On platforms that don't support a shadow, the rounded border of the app |
| 376 // list is constructed _inside_ the view, so a rectangular background goes | 395 // list is constructed _inside_ the view, so a rectangular background goes |
| 377 // over the border in the rounded corners. To fix this, give the background a | 396 // over the border in the rounded corners. To fix this, give the background a |
| 378 // corner radius 1px smaller than the outer border, so it just reaches but | 397 // corner radius 1px smaller than the outer border, so it just reaches but |
| 379 // doesn't cover it. | 398 // doesn't cover it. |
| 380 const int kOverlayCornerRadius = | 399 const int kOverlayCornerRadius = |
| 381 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); | 400 GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); |
| 382 overlay_view_->set_background(new AppListOverlayBackground( | 401 overlay_view_->set_background(new AppListOverlayBackground( |
| 383 kOverlayCornerRadius - (SupportsShadow() ? 0 : 1))); | 402 kOverlayCornerRadius - (SupportsShadow() ? 0 : 1))); |
| 384 AddChildView(overlay_view_); | 403 AddChildView(overlay_view_); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 gfx::Transform speech_transform; | 553 gfx::Transform speech_transform; |
| 535 speech_transform.Translate( | 554 speech_transform.Translate( |
| 536 0, SkFloatToMScalar(kSpeechUIAppearingPosition)); | 555 0, SkFloatToMScalar(kSpeechUIAppearingPosition)); |
| 537 if (will_appear) | 556 if (will_appear) |
| 538 speech_view_->layer()->SetTransform(speech_transform); | 557 speech_view_->layer()->SetTransform(speech_transform); |
| 539 | 558 |
| 540 { | 559 { |
| 541 ui::ScopedLayerAnimationSettings main_settings( | 560 ui::ScopedLayerAnimationSettings main_settings( |
| 542 app_list_main_view_->layer()->GetAnimator()); | 561 app_list_main_view_->layer()->GetAnimator()); |
| 543 if (will_appear) { | 562 if (will_appear) { |
| 544 animation_observer_->SetTarget(app_list_main_view_); | 563 animation_observer_->AddTarget(app_list_main_view_); |
| 545 main_settings.AddObserver(animation_observer_.get()); | 564 main_settings.AddObserver(animation_observer_.get()); |
| 546 } | 565 } |
| 547 app_list_main_view_->layer()->SetOpacity(will_appear ? 0.0f : 1.0f); | 566 app_list_main_view_->layer()->SetOpacity(will_appear ? 0.0f : 1.0f); |
| 548 } | 567 } |
| 549 | 568 |
| 550 { | 569 { |
| 551 ui::ScopedLayerAnimationSettings speech_settings( | 570 ui::ScopedLayerAnimationSettings speech_settings( |
| 552 speech_view_->layer()->GetAnimator()); | 571 speech_view_->layer()->GetAnimator()); |
| 553 if (!will_appear) { | 572 if (!will_appear) { |
| 554 animation_observer_->SetTarget(speech_view_); | 573 animation_observer_->AddTarget(speech_view_); |
| 555 speech_settings.AddObserver(animation_observer_.get()); | 574 speech_settings.AddObserver(animation_observer_.get()); |
| 556 } | 575 } |
| 557 | 576 |
| 558 speech_view_->layer()->SetOpacity(will_appear ? 1.0f : 0.0f); | 577 speech_view_->layer()->SetOpacity(will_appear ? 1.0f : 0.0f); |
| 559 if (will_appear) | 578 if (will_appear) |
| 560 speech_view_->layer()->SetTransform(gfx::Transform()); | 579 speech_view_->layer()->SetTransform(gfx::Transform()); |
| 561 else | 580 else |
| 562 speech_view_->layer()->SetTransform(speech_transform); | 581 speech_view_->layer()->SetTransform(speech_transform); |
| 563 } | 582 } |
| 564 | 583 |
| 565 if (will_appear) | 584 if (will_appear) |
| 566 speech_view_->SetVisible(true); | 585 speech_view_->SetVisible(true); |
| 567 else | 586 else |
| 568 app_list_main_view_->SetVisible(true); | 587 app_list_main_view_->SetVisible(true); |
| 569 } | 588 } |
| 570 | 589 |
| 571 } // namespace app_list | 590 } // namespace app_list |
| OLD | NEW |