OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/wm/overview/window_selector_item.h" | 5 #include "ash/wm/overview/window_selector_item.h" |
| 6 |
| 7 #include "ash/screen_util.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/wm/overview/scoped_transform_overview_window.h" |
6 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" |
7 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 16 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/layout/box_layout.h" |
| 18 #include "ui/views/widget/widget.h" |
8 | 19 |
9 namespace ash { | 20 namespace ash { |
10 | 21 |
| 22 // Foreground label color. |
| 23 static const SkColor kLabelColor = SK_ColorWHITE; |
| 24 |
| 25 // Background label color. |
| 26 static const SkColor kLabelBackground = SK_ColorTRANSPARENT; |
| 27 |
| 28 // Label shadow color. |
| 29 static const SkColor kLabelShadow = 0xB0000000; |
| 30 |
| 31 // Vertical padding for the label, both over and beneath it. |
| 32 static const int kVerticalLabelPadding = 20; |
| 33 |
| 34 // Solid shadow length from the label |
| 35 static const int kVerticalShadowOffset = 1; |
| 36 |
| 37 // Amount of blur applied to the label shadow |
| 38 static const int kShadowBlur = 10; |
| 39 |
| 40 views::Widget* CreateWindowLabel(aura::Window* root_window, |
| 41 const base::string16 title) { |
| 42 views::Widget* widget = new views::Widget; |
| 43 views::Widget::InitParams params; |
| 44 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 45 params.can_activate = false; |
| 46 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 47 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 48 params.parent = |
| 49 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); |
| 50 params.accept_events = false; |
| 51 params.visible_on_all_workspaces = true; |
| 52 widget->set_focus_on_creation(false); |
| 53 widget->Init(params); |
| 54 views::Label* label = new views::Label; |
| 55 label->SetEnabledColor(kLabelColor); |
| 56 label->SetBackgroundColor(kLabelBackground); |
| 57 label->SetShadowColors(kLabelShadow, kLabelShadow); |
| 58 label->SetShadowOffset(0, kVerticalShadowOffset); |
| 59 label->set_shadow_blur(kShadowBlur); |
| 60 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 61 label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); |
| 62 label->SetText(title); |
| 63 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, |
| 64 0, |
| 65 kVerticalLabelPadding, |
| 66 0); |
| 67 label->SetLayoutManager(layout); |
| 68 widget->SetContentsView(label); |
| 69 widget->Show(); |
| 70 return widget; |
| 71 } |
| 72 |
| 73 const int WindowSelectorItem::kFadeInMilliseconds = 80; |
| 74 |
11 WindowSelectorItem::WindowSelectorItem() | 75 WindowSelectorItem::WindowSelectorItem() |
12 : root_window_(NULL), | 76 : root_window_(NULL), |
13 in_bounds_update_(false) { | 77 in_bounds_update_(false) { |
14 } | 78 } |
15 | 79 |
16 WindowSelectorItem::~WindowSelectorItem() { | 80 WindowSelectorItem::~WindowSelectorItem() { |
17 } | 81 } |
18 | 82 |
19 void WindowSelectorItem::SetBounds(aura::Window* root_window, | 83 void WindowSelectorItem::SetBounds(aura::Window* root_window, |
20 const gfx::Rect& target_bounds) { | 84 const gfx::Rect& target_bounds) { |
21 if (in_bounds_update_) | 85 if (in_bounds_update_) |
22 return; | 86 return; |
23 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | 87 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
24 root_window_ = root_window; | 88 root_window_ = root_window; |
25 target_bounds_ = target_bounds; | 89 target_bounds_ = target_bounds; |
26 SetItemBounds(root_window, target_bounds, true); | 90 SetItemBounds(root_window, target_bounds, true); |
| 91 // TODO(nsatragno): Handle window title updates. |
| 92 UpdateWindowLabels(target_bounds, root_window); |
27 } | 93 } |
28 | 94 |
29 void WindowSelectorItem::RecomputeWindowTransforms() { | 95 void WindowSelectorItem::RecomputeWindowTransforms() { |
30 if (in_bounds_update_ || target_bounds_.IsEmpty()) | 96 if (in_bounds_update_ || target_bounds_.IsEmpty()) |
31 return; | 97 return; |
32 DCHECK(root_window_); | 98 DCHECK(root_window_); |
33 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | 99 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
34 SetItemBounds(root_window_, target_bounds_, false); | 100 SetItemBounds(root_window_, target_bounds_, false); |
35 } | 101 } |
36 | 102 |
| 103 void WindowSelectorItem::UpdateWindowLabels(const gfx::Rect& window_bounds, |
| 104 aura::Window* root_window) { |
| 105 gfx::Rect converted_bounds = ScreenUtil::ConvertRectFromScreen(root_window, |
| 106 window_bounds); |
| 107 gfx::Rect label_bounds(converted_bounds.x(), |
| 108 converted_bounds.bottom(), |
| 109 converted_bounds.width(), |
| 110 0); |
| 111 |
| 112 // If the root window has changed, force the window label to be recreated |
| 113 // and faded in on the new root window. |
| 114 if (window_label_ && |
| 115 window_label_->GetNativeWindow()->GetRootWindow() != root_window) { |
| 116 window_label_.reset(); |
| 117 } |
| 118 |
| 119 if (!window_label_) { |
| 120 window_label_.reset(CreateWindowLabel(root_window, |
| 121 SelectionWindow()->title())); |
| 122 label_bounds.set_height(window_label_-> |
| 123 GetContentsView()->GetPreferredSize().height()); |
| 124 window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| 125 ui::Layer* layer = window_label_->GetNativeWindow()->layer(); |
| 126 |
| 127 layer->SetOpacity(0); |
| 128 layer->GetAnimator()->StopAnimating(); |
| 129 |
| 130 layer->GetAnimator()->SchedulePauseForProperties( |
| 131 base::TimeDelta::FromMilliseconds( |
| 132 ScopedTransformOverviewWindow::kTransitionMilliseconds), |
| 133 ui::LayerAnimationElement::OPACITY); |
| 134 |
| 135 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| 136 settings.SetPreemptionStrategy( |
| 137 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 138 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 139 kFadeInMilliseconds)); |
| 140 layer->SetOpacity(1); |
| 141 } else { |
| 142 ui::ScopedLayerAnimationSettings settings( |
| 143 window_label_->GetNativeWindow()->layer()->GetAnimator()); |
| 144 settings.SetPreemptionStrategy( |
| 145 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 146 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 147 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
| 148 label_bounds.set_height(window_label_-> |
| 149 GetContentsView()->GetPreferredSize().height()); |
| 150 window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| 151 } |
| 152 |
| 153 } |
| 154 |
37 } // namespace ash | 155 } // namespace ash |
OLD | NEW |