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