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