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_window.h" | 5 #include "ash/wm/overview/window_selector_window.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/wm/overview/scoped_transform_overview_window.h" | 9 #include "ash/wm/overview/scoped_transform_overview_window.h" |
10 #include "grit/ash_resources.h" | 10 #include "grit/ash_resources.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/compositor/scoped_layer_animation_settings.h" | 13 #include "ui/compositor/scoped_layer_animation_settings.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
15 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
16 #include "ui/views/controls/button/image_button.h" | 16 #include "ui/views/controls/button/image_button.h" |
17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 views::Widget* CreateWindowLabel(aura::Window* root_window, | |
24 const base::string16 title) { | |
25 views::Widget* widget = new views::Widget; | |
26 views::Widget::InitParams params; | |
27 params.type = views::Widget::InitParams::TYPE_POPUP; | |
28 params.can_activate = false; | |
29 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
30 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | |
31 params.parent = | |
32 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | |
33 widget->set_focus_on_creation(false); | |
34 widget->Init(params); | |
35 views::Label* label = new views::Label; | |
36 label->SetEnabledColor(WindowSelectorWindow::kLabelColor); | |
37 label->SetBackgroundColor(WindowSelectorWindow::kLabelBackground); | |
38 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
39 label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); | |
40 label->SetText(title); | |
41 widget->SetContentsView(label); | |
42 widget->Show(); | |
43 return widget; | |
44 } | |
45 | |
23 views::Widget* CreateCloseWindowButton(aura::Window* root_window, | 46 views::Widget* CreateCloseWindowButton(aura::Window* root_window, |
24 views::ButtonListener* listener) { | 47 views::ButtonListener* listener) { |
25 views::Widget* widget = new views::Widget; | 48 views::Widget* widget = new views::Widget; |
26 views::Widget::InitParams params; | 49 views::Widget::InitParams params; |
27 params.type = views::Widget::InitParams::TYPE_POPUP; | 50 params.type = views::Widget::InitParams::TYPE_POPUP; |
28 params.can_activate = false; | 51 params.can_activate = false; |
29 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 52 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
30 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 53 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
31 params.parent = | 54 params.parent = |
32 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | 55 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 } | 118 } |
96 | 119 |
97 void WindowSelectorWindow::PrepareForOverview() { | 120 void WindowSelectorWindow::PrepareForOverview() { |
98 transform_window_.PrepareForOverview(); | 121 transform_window_.PrepareForOverview(); |
99 } | 122 } |
100 | 123 |
101 void WindowSelectorWindow::SetItemBounds(aura::Window* root_window, | 124 void WindowSelectorWindow::SetItemBounds(aura::Window* root_window, |
102 const gfx::Rect& target_bounds, | 125 const gfx::Rect& target_bounds, |
103 bool animate) { | 126 bool animate) { |
104 gfx::Rect src_rect = transform_window_.GetBoundsInScreen(); | 127 gfx::Rect src_rect = transform_window_.GetBoundsInScreen(); |
105 set_bounds(ScopedTransformOverviewWindow:: | 128 const gfx::Rect window_bounds = |
106 ShrinkRectToFitPreservingAspectRatio(src_rect, target_bounds)); | 129 ScopedTransformOverviewWindow:: |
130 ShrinkRectToFitPreservingAspectRatio(src_rect, target_bounds); | |
131 set_bounds(window_bounds); | |
107 transform_window_.SetTransform(root_window, | 132 transform_window_.SetTransform(root_window, |
108 ScopedTransformOverviewWindow::GetTransformForRect(src_rect, bounds()), | 133 ScopedTransformOverviewWindow::GetTransformForRect(src_rect, bounds()), |
109 animate); | 134 animate); |
135 UpdateWindowLabels(window_bounds); | |
110 UpdateCloseButtonBounds(); | 136 UpdateCloseButtonBounds(); |
111 } | 137 } |
112 | 138 |
113 void WindowSelectorWindow::ButtonPressed(views::Button* sender, | 139 void WindowSelectorWindow::ButtonPressed(views::Button* sender, |
114 const ui::Event& event) { | 140 const ui::Event& event) { |
115 views::Widget::GetTopLevelWidgetForNativeView( | 141 views::Widget::GetTopLevelWidgetForNativeView( |
116 transform_window_.window())->Close(); | 142 transform_window_.window())->Close(); |
117 } | 143 } |
118 | 144 |
145 void WindowSelectorWindow::UpdateWindowLabels(const gfx::Rect& window_bounds) { | |
146 // TODO Animate the labels with some cute effects | |
147 base::string16 window_title = transform_window_.window()->title(); | |
148 if (!window_label_) | |
149 window_label_.reset(CreateWindowLabel(GetRootWindow(), window_title)); | |
150 // TODO use constant for box height? Calculate dynamically? | |
tdanderson
2014/04/09 20:35:17
I suspect that we'll eventually want to calculate
| |
151 gfx::Rect label_bounds(window_bounds.x(), | |
152 window_bounds.y() + window_bounds.height(), | |
153 window_bounds.width(), | |
154 40); | |
155 window_label_->GetNativeWindow()->SetBounds(label_bounds); | |
156 } | |
157 | |
119 void WindowSelectorWindow::UpdateCloseButtonBounds() { | 158 void WindowSelectorWindow::UpdateCloseButtonBounds() { |
120 aura::Window* root_window = GetRootWindow(); | 159 aura::Window* root_window = GetRootWindow(); |
121 gfx::Rect align_bounds(bounds()); | 160 gfx::Rect align_bounds(bounds()); |
122 gfx::Transform close_button_transform; | 161 gfx::Transform close_button_transform; |
123 close_button_transform.Translate(align_bounds.right(), align_bounds.y()); | 162 close_button_transform.Translate(align_bounds.right(), align_bounds.y()); |
124 | 163 |
125 // If the root window has changed, force the close button to be recreated | 164 // If the root window has changed, force the close button to be recreated |
126 // and faded in on the new root window. | 165 // and faded in on the new root window. |
127 if (close_button_ && | 166 if (close_button_ && |
128 close_button_->GetNativeWindow()->GetRootWindow() != root_window) { | 167 close_button_->GetNativeWindow()->GetRootWindow() != root_window) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 close_button_->GetNativeWindow()->layer()->GetAnimator()); | 200 close_button_->GetNativeWindow()->layer()->GetAnimator()); |
162 settings.SetPreemptionStrategy( | 201 settings.SetPreemptionStrategy( |
163 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 202 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
164 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 203 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
165 ScopedTransformOverviewWindow::kTransitionMilliseconds)); | 204 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
166 close_button_->GetNativeWindow()->SetTransform(close_button_transform); | 205 close_button_->GetNativeWindow()->SetTransform(close_button_transform); |
167 } | 206 } |
168 } | 207 } |
169 | 208 |
170 } // namespace ash | 209 } // namespace ash |
OLD | NEW |