Chromium Code Reviews| 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 | 6 |
| 7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/wm/overview/scoped_transform_overview_window.h" | 10 #include "ash/wm/overview/scoped_transform_overview_window.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 66 |
| 67 // Vertical padding for the label, both over and beneath it. | 67 // Vertical padding for the label, both over and beneath it. |
| 68 static const int kVerticalLabelPadding = 20; | 68 static const int kVerticalLabelPadding = 20; |
| 69 | 69 |
| 70 // Solid shadow length from the label | 70 // Solid shadow length from the label |
| 71 static const int kVerticalShadowOffset = 1; | 71 static const int kVerticalShadowOffset = 1; |
| 72 | 72 |
| 73 // Amount of blur applied to the label shadow | 73 // Amount of blur applied to the label shadow |
| 74 static const int kShadowBlur = 10; | 74 static const int kShadowBlur = 10; |
| 75 | 75 |
| 76 views::Widget* CreateWindowLabel(aura::Window* root_window, | |
| 77 const base::string16 title) { | |
| 78 views::Widget* widget = new views::Widget; | |
| 79 views::Widget::InitParams params; | |
| 80 params.type = views::Widget::InitParams::TYPE_POPUP; | |
| 81 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 82 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 83 params.parent = | |
| 84 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | |
| 85 params.accept_events = false; | |
| 86 params.visible_on_all_workspaces = true; | |
| 87 widget->set_focus_on_creation(false); | |
| 88 widget->Init(params); | |
| 89 views::Label* label = new views::Label; | |
| 90 label->SetEnabledColor(kLabelColor); | |
| 91 label->SetBackgroundColor(kLabelBackground); | |
| 92 label->set_shadows(gfx::ShadowValues(1, gfx::ShadowValue( | |
| 93 gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kLabelShadow))); | |
| 94 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 95 label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); | |
| 96 label->SetText(title); | |
| 97 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, | |
| 98 0, | |
| 99 kVerticalLabelPadding, | |
| 100 0); | |
| 101 label->SetLayoutManager(layout); | |
| 102 widget->SetContentsView(label); | |
| 103 widget->Show(); | |
| 104 return widget; | |
| 105 } | |
| 106 | |
| 107 const int WindowSelectorItem::kFadeInMilliseconds = 80; | 76 const int WindowSelectorItem::kFadeInMilliseconds = 80; |
| 108 | 77 |
| 109 WindowSelectorItem::WindowSelectorItem() | 78 WindowSelectorItem::WindowSelectorItem() |
| 110 : root_window_(NULL), | 79 : root_window_(NULL), |
| 111 in_bounds_update_(false) { | 80 in_bounds_update_(false), |
| 81 window_label_view_(NULL) { | |
|
Nina
2014/06/25 19:54:40
This is so that the tests fail gracefully if, for
| |
| 112 } | 82 } |
| 113 | 83 |
| 114 WindowSelectorItem::~WindowSelectorItem() { | 84 WindowSelectorItem::~WindowSelectorItem() { |
| 115 } | 85 } |
| 116 | 86 |
| 117 void WindowSelectorItem::RemoveWindow(const aura::Window* window) { | 87 void WindowSelectorItem::RemoveWindow(const aura::Window* window) { |
| 118 // If empty WindowSelectorItem will be destroyed immediately after this by | 88 // If empty WindowSelectorItem will be destroyed immediately after this by |
| 119 // its owner. | 89 // its owner. |
| 120 if (empty()) | 90 if (empty()) |
| 121 return; | 91 return; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 134 target_bounds_ = target_bounds; | 104 target_bounds_ = target_bounds; |
| 135 | 105 |
| 136 // Set the bounds of the transparent window handler to cover the entire | 106 // Set the bounds of the transparent window handler to cover the entire |
| 137 // bounding box area. | 107 // bounding box area. |
| 138 if (!activate_window_button_) { | 108 if (!activate_window_button_) { |
| 139 activate_window_button_.reset( | 109 activate_window_button_.reset( |
| 140 new TransparentActivateWindowButton(SelectionWindow())); | 110 new TransparentActivateWindowButton(SelectionWindow())); |
| 141 } | 111 } |
| 142 activate_window_button_->SetBounds(target_bounds); | 112 activate_window_button_->SetBounds(target_bounds); |
| 143 | 113 |
| 144 // TODO(nsatragno): Handle window title updates. | |
| 145 UpdateWindowLabels(target_bounds, root_window, animate); | 114 UpdateWindowLabels(target_bounds, root_window, animate); |
| 146 | 115 |
| 147 gfx::Rect inset_bounds(target_bounds); | 116 gfx::Rect inset_bounds(target_bounds); |
| 148 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 117 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| 149 SetItemBounds(root_window, inset_bounds, animate); | 118 SetItemBounds(root_window, inset_bounds, animate); |
| 150 UpdateCloseButtonBounds(root_window, animate); | 119 UpdateCloseButtonBounds(root_window, animate); |
| 151 } | 120 } |
| 152 | 121 |
| 153 void WindowSelectorItem::RecomputeWindowTransforms() { | 122 void WindowSelectorItem::RecomputeWindowTransforms() { |
| 154 if (in_bounds_update_ || target_bounds_.IsEmpty()) | 123 if (in_bounds_update_ || target_bounds_.IsEmpty()) |
| 155 return; | 124 return; |
| 156 DCHECK(root_window_); | 125 DCHECK(root_window_); |
| 157 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); | 126 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
| 158 gfx::Rect inset_bounds(target_bounds_); | 127 gfx::Rect inset_bounds(target_bounds_); |
| 159 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 128 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| 160 SetItemBounds(root_window_, inset_bounds, false); | 129 SetItemBounds(root_window_, inset_bounds, false); |
| 161 UpdateCloseButtonBounds(root_window_, false); | 130 UpdateCloseButtonBounds(root_window_, false); |
| 162 } | 131 } |
| 163 | 132 |
| 164 void WindowSelectorItem::SendFocusAlert() const { | 133 void WindowSelectorItem::SendFocusAlert() const { |
| 165 activate_window_button_->SendFocusAlert(); | 134 activate_window_button_->SendFocusAlert(); |
| 166 } | 135 } |
| 167 | 136 |
| 168 void WindowSelectorItem::ButtonPressed(views::Button* sender, | 137 void WindowSelectorItem::ButtonPressed(views::Button* sender, |
| 169 const ui::Event& event) { | 138 const ui::Event& event) { |
| 170 views::Widget::GetWidgetForNativeView(SelectionWindow())->Close(); | 139 views::Widget::GetWidgetForNativeView(SelectionWindow())->Close(); |
| 171 } | 140 } |
| 172 | 141 |
| 142 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { | |
| 143 if (window == SelectionWindow()) | |
| 144 window_label_view_->SetText(window->title()); | |
| 145 } | |
| 146 | |
| 173 void WindowSelectorItem::UpdateCloseButtonBounds(aura::Window* root_window, | 147 void WindowSelectorItem::UpdateCloseButtonBounds(aura::Window* root_window, |
| 174 bool animate) { | 148 bool animate) { |
| 175 gfx::RectF align_bounds(ScreenUtil::ConvertRectFromScreen( | 149 gfx::RectF align_bounds(ScreenUtil::ConvertRectFromScreen( |
| 176 root_window, SelectionWindow()->layer()->bounds())); | 150 root_window, SelectionWindow()->layer()->bounds())); |
| 177 gfx::Transform window_transform; | 151 gfx::Transform window_transform; |
| 178 window_transform.Translate(align_bounds.x(), align_bounds.y()); | 152 window_transform.Translate(align_bounds.x(), align_bounds.y()); |
| 179 window_transform.PreconcatTransform(SelectionWindow()->layer()-> | 153 window_transform.PreconcatTransform(SelectionWindow()->layer()-> |
| 180 GetTargetTransform()); | 154 GetTargetTransform()); |
| 181 window_transform.Translate(-align_bounds.x(), -align_bounds.y()); | 155 window_transform.Translate(-align_bounds.x(), -align_bounds.y()); |
| 182 window_transform.TransformRect(&align_bounds); | 156 window_transform.TransformRect(&align_bounds); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 0); | 219 0); |
| 246 | 220 |
| 247 // If the root window has changed, force the window label to be recreated | 221 // If the root window has changed, force the window label to be recreated |
| 248 // and faded in on the new root window. | 222 // and faded in on the new root window. |
| 249 if (window_label_ && | 223 if (window_label_ && |
| 250 window_label_->GetNativeWindow()->GetRootWindow() != root_window) { | 224 window_label_->GetNativeWindow()->GetRootWindow() != root_window) { |
| 251 window_label_.reset(); | 225 window_label_.reset(); |
| 252 } | 226 } |
| 253 | 227 |
| 254 if (!window_label_) { | 228 if (!window_label_) { |
| 255 window_label_.reset(CreateWindowLabel(root_window, | 229 CreateWindowLabel(SelectionWindow()->title()); |
| 256 SelectionWindow()->title())); | 230 label_bounds.set_height(window_label_view_->GetPreferredSize().height()); |
| 257 label_bounds.set_height(window_label_-> | 231 label_bounds.set_y(label_bounds.y() - window_label_view_-> |
| 258 GetContentsView()->GetPreferredSize().height()); | 232 GetPreferredSize().height()); |
| 259 label_bounds.set_y(label_bounds.y() - window_label_-> | |
| 260 GetContentsView()->GetPreferredSize().height()); | |
| 261 window_label_->GetNativeWindow()->SetBounds(label_bounds); | 233 window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| 262 ui::Layer* layer = window_label_->GetNativeWindow()->layer(); | 234 ui::Layer* layer = window_label_->GetNativeWindow()->layer(); |
| 263 | 235 |
| 264 layer->SetOpacity(0); | 236 layer->SetOpacity(0); |
| 265 layer->GetAnimator()->StopAnimating(); | 237 layer->GetAnimator()->StopAnimating(); |
| 266 | 238 |
| 267 layer->GetAnimator()->SchedulePauseForProperties( | 239 layer->GetAnimator()->SchedulePauseForProperties( |
| 268 base::TimeDelta::FromMilliseconds( | 240 base::TimeDelta::FromMilliseconds( |
| 269 ScopedTransformOverviewWindow::kTransitionMilliseconds), | 241 ScopedTransformOverviewWindow::kTransitionMilliseconds), |
| 270 ui::LayerAnimationElement::OPACITY); | 242 ui::LayerAnimationElement::OPACITY); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 287 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 259 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 288 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 260 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 289 ScopedTransformOverviewWindow::kTransitionMilliseconds)); | 261 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
| 290 window_label_->GetNativeWindow()->SetBounds(label_bounds); | 262 window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| 291 } else { | 263 } else { |
| 292 window_label_->GetNativeWindow()->SetBounds(label_bounds); | 264 window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| 293 } | 265 } |
| 294 } | 266 } |
| 295 } | 267 } |
| 296 | 268 |
| 269 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { | |
| 270 window_label_.reset(new views::Widget); | |
| 271 views::Widget::InitParams params; | |
| 272 params.type = views::Widget::InitParams::TYPE_POPUP; | |
| 273 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 274 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 275 params.parent = | |
| 276 Shell::GetContainer(root_window_, ash::kShellWindowId_OverlayContainer); | |
| 277 params.accept_events = false; | |
| 278 params.visible_on_all_workspaces = true; | |
| 279 window_label_->set_focus_on_creation(false); | |
| 280 window_label_->Init(params); | |
| 281 window_label_view_ = new views::Label; | |
| 282 window_label_view_->SetEnabledColor(kLabelColor); | |
| 283 window_label_view_->SetBackgroundColor(kLabelBackground); | |
| 284 window_label_view_->set_shadows(gfx::ShadowValues(1, gfx::ShadowValue( | |
| 285 gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kLabelShadow))); | |
| 286 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 287 window_label_view_->SetFontList( | |
| 288 bundle.GetFontList(ui::ResourceBundle::BoldFont)); | |
| 289 window_label_view_->SetText(title); | |
| 290 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, | |
| 291 0, | |
| 292 kVerticalLabelPadding, | |
| 293 0); | |
| 294 window_label_view_->SetLayoutManager(layout); | |
| 295 window_label_->SetContentsView(window_label_view_); | |
| 296 window_label_->Show(); | |
| 297 } | |
| 298 | |
| 297 } // namespace ash | 299 } // namespace ash |
| OLD | NEW |