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