Chromium Code Reviews| Index: ash/wm/overview/window_selector_item.cc |
| diff --git a/ash/wm/overview/window_selector_item.cc b/ash/wm/overview/window_selector_item.cc |
| index a2c25b617e9c872b1c2849209cc383ff59a14657..e726504d0959ed7b8e64ae4c3a44f62877e378e6 100644 |
| --- a/ash/wm/overview/window_selector_item.cc |
| +++ b/ash/wm/overview/window_selector_item.cc |
| @@ -2,12 +2,66 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "ash/shell.h" |
| +#include "ash/shell_window_ids.h" |
| +#include "ash/wm/overview/scoped_transform_overview_window.h" |
| #include "ash/wm/overview/window_selector_item.h" |
|
tdanderson
2014/04/10 22:37:12
It is proper form for the first #include in a .cc
Nina
2014/04/14 16:24:04
Done.
|
| #include "base/auto_reset.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| #include "ui/aura/window.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/compositor/scoped_layer_animation_settings.h" |
| +#include "ui/views/controls/label.h" |
| +#include "ui/views/layout/box_layout.h" |
| +#include "ui/views/widget/widget.h" |
| namespace ash { |
| +// Foreground label color. |
| +static const SkColor kLabelColor = SK_ColorWHITE; |
| + |
| +// Background label color. |
| +static const SkColor kLabelBackground = SK_ColorTRANSPARENT; |
| + |
| +// Label shadow color. |
| +static const SkColor kLabelShadow = SK_ColorBLACK; |
| + |
| +// Vertical padding for the label, both over and beneath it. |
| +static const int kVerticalLabelPadding = 20; |
| + |
| +// Label height, ie. distance from the border of the window to the label bottom. |
| +static const int kLabelHeight = 20; |
| + |
| +views::Widget* CreateWindowLabel(aura::Window* root_window, |
| + const base::string16 title) { |
| + views::Widget* widget = new views::Widget; |
| + views::Widget::InitParams params; |
| + params.type = views::Widget::InitParams::TYPE_POPUP; |
| + params.can_activate = false; |
| + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| + params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| + params.parent = |
|
tdanderson
2014/04/10 22:37:12
Let's also explicitly say params.accept_events = f
Nina
2014/04/14 16:24:04
Done.
|
| + Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); |
| + widget->set_focus_on_creation(false); |
| + widget->Init(params); |
| + views::Label* label = new views::Label; |
| + label->SetEnabledColor(kLabelColor); |
| + label->SetBackgroundColor(kLabelBackground); |
| + label->SetShadowColors(kLabelShadow, kLabelShadow); |
| + label->SetShadowOffset(0, 1); |
| + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| + label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); |
| + label->SetText(title); |
| + views::BoxLayout* layout = new views::BoxLayout( |
| + views::BoxLayout::kVertical, |
| + 0, kVerticalLabelPadding, 0); |
|
tdanderson
2014/04/10 22:37:12
My preference here would be to have one argument p
Nina
2014/04/14 16:24:04
Done.
|
| + label->SetLayoutManager(layout); |
| + widget->SetContentsView(label); |
| + widget->Show(); |
| + return widget; |
| +} |
| + |
| WindowSelectorItem::WindowSelectorItem() |
| : root_window_(NULL), |
| in_bounds_update_(false) { |
| @@ -24,6 +78,7 @@ void WindowSelectorItem::SetBounds(aura::Window* root_window, |
| root_window_ = root_window; |
| target_bounds_ = target_bounds; |
| SetItemBounds(root_window, target_bounds, true); |
| + UpdateWindowLabels(target_bounds); |
| } |
| void WindowSelectorItem::RecomputeWindowTransforms() { |
| @@ -34,4 +89,54 @@ void WindowSelectorItem::RecomputeWindowTransforms() { |
| SetItemBounds(root_window_, target_bounds_, false); |
| } |
| +void WindowSelectorItem::UpdateWindowLabels(const gfx::Rect& window_bounds) { |
| + aura::Window* root_window = GetRootWindow(); |
| + |
| + gfx::Rect label_bounds(window_bounds.x(), |
| + window_bounds.y() + window_bounds.height(), |
| + window_bounds.width(), |
| + kLabelHeight); |
| + |
| + // If the root window has changed, force the window label to be recreated |
| + // and faded in on the new root window. |
| + if (window_label_ && |
| + window_label_->GetNativeWindow()->GetRootWindow() != root_window) { |
| + window_label_.reset(); |
| + } |
| + |
| + if (!window_label_) { |
| + window_label_.reset(CreateWindowLabel(GetRootWindow(), GetLabelName())); |
| + window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| + ui::Layer* layer = window_label_->GetNativeWindow()->layer(); |
| + |
| + layer->SetOpacity(0); |
| + layer->GetAnimator()->StopAnimating(); |
| + |
| + layer->GetAnimator()->SchedulePauseForProperties( |
| + base::TimeDelta::FromMilliseconds( |
| + ScopedTransformOverviewWindow::kTransitionMilliseconds), |
| + ui::LayerAnimationElement::OPACITY); |
| + { |
|
tdanderson
2014/04/10 22:37:12
I am not 100% sure I understand why lines 120-125
Nina
2014/04/14 16:24:04
I don't know either, but that's how the animation
|
| + ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| + settings.SetPreemptionStrategy( |
| + ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| + settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| + ScopedTransformOverviewWindow::kFadeInMilliseconds)); |
| + layer->SetOpacity(1); |
| + } |
| + } else { |
| + gfx::Transform window_label_transform = |
| + ScopedTransformOverviewWindow::GetTransformForRect( |
| + window_label_->GetNativeWindow()->bounds(), label_bounds); |
| + ui::ScopedLayerAnimationSettings settings( |
| + window_label_->GetNativeWindow()->layer()->GetAnimator()); |
| + settings.SetPreemptionStrategy( |
| + ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| + settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| + ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
| + window_label_->GetNativeWindow()->SetTransform(window_label_transform); |
| + } |
| + |
| +} |
| + |
| } // namespace ash |