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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 const int WindowSelectorItem::kFadeInMilliseconds = 80; | 76 const int WindowSelectorItem::kFadeInMilliseconds = 80; |
| 77 | 77 |
| 78 // Opacity for dimmed items. | |
| 79 static const float kDimmedItemOpacity = 0.5; | |
| 80 | |
| 81 views::Widget* CreateWindowLabel(aura::Window* root_window, | |
| 82 const base::string16 title) { | |
| 83 views::Widget* widget = new views::Widget; | |
| 84 views::Widget::InitParams params; | |
| 85 params.type = views::Widget::InitParams::TYPE_POPUP; | |
| 86 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 87 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 88 params.parent = | |
| 89 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | |
| 90 params.accept_events = false; | |
| 91 params.visible_on_all_workspaces = true; | |
| 92 widget->set_focus_on_creation(false); | |
| 93 widget->Init(params); | |
| 94 views::Label* label = new views::Label; | |
| 95 label->SetEnabledColor(kLabelColor); | |
| 96 label->SetBackgroundColor(kLabelBackground); | |
| 97 label->set_shadows(gfx::ShadowValues(1, gfx::ShadowValue( | |
| 98 gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kLabelShadow))); | |
| 99 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 100 label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); | |
| 101 label->SetText(title); | |
| 102 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, | |
| 103 0, | |
| 104 kVerticalLabelPadding, | |
| 105 0); | |
| 106 label->SetLayoutManager(layout); | |
| 107 widget->SetContentsView(label); | |
| 108 widget->Show(); | |
| 109 return widget; | |
| 110 } | |
| 111 | |
| 78 WindowSelectorItem::WindowSelectorItem() | 112 WindowSelectorItem::WindowSelectorItem() |
| 79 : root_window_(NULL), | 113 : dimmed_(false), |
| 114 root_window_(NULL), | |
| 80 in_bounds_update_(false), | 115 in_bounds_update_(false), |
| 81 window_label_view_(NULL) { | 116 window_label_view_(NULL) { |
| 82 } | 117 } |
| 83 | 118 |
| 84 WindowSelectorItem::~WindowSelectorItem() { | 119 WindowSelectorItem::~WindowSelectorItem() { |
| 85 } | 120 } |
| 86 | 121 |
| 87 void WindowSelectorItem::RemoveWindow(const aura::Window* window) { | 122 void WindowSelectorItem::RemoveWindow(const aura::Window* window) { |
| 88 // If empty WindowSelectorItem will be destroyed immediately after this by | 123 // If empty WindowSelectorItem will be destroyed immediately after this by |
| 89 // its owner. | 124 // its owner. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 gfx::Rect inset_bounds(target_bounds_); | 162 gfx::Rect inset_bounds(target_bounds_); |
| 128 inset_bounds.Inset(kWindowMargin, kWindowMargin); | 163 inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| 129 SetItemBounds(root_window_, inset_bounds, false); | 164 SetItemBounds(root_window_, inset_bounds, false); |
| 130 UpdateCloseButtonBounds(root_window_, false); | 165 UpdateCloseButtonBounds(root_window_, false); |
| 131 } | 166 } |
| 132 | 167 |
| 133 void WindowSelectorItem::SendFocusAlert() const { | 168 void WindowSelectorItem::SendFocusAlert() const { |
| 134 activate_window_button_->SendFocusAlert(); | 169 activate_window_button_->SendFocusAlert(); |
| 135 } | 170 } |
| 136 | 171 |
| 172 void WindowSelectorItem::SetDimmed(bool dimmed) { | |
| 173 dimmed_ = dimmed; | |
| 174 SetOpacity(dimmed ? kDimmedItemOpacity : 1); | |
|
flackr
2014/06/27 20:00:07
nit: Use 1.0f as this is used as a float.
Nina
2014/06/27 22:42:02
Done.
| |
| 175 } | |
| 176 | |
| 137 void WindowSelectorItem::ButtonPressed(views::Button* sender, | 177 void WindowSelectorItem::ButtonPressed(views::Button* sender, |
| 138 const ui::Event& event) { | 178 const ui::Event& event) { |
| 139 views::Widget::GetWidgetForNativeView(SelectionWindow())->Close(); | 179 views::Widget::GetWidgetForNativeView(SelectionWindow())->Close(); |
| 140 } | 180 } |
| 141 | 181 |
| 142 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { | 182 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { |
| 183 // TODO(flackr): Maybe update dimmed / undimmed status when the label is | |
| 184 // updated? | |
| 143 if (window == SelectionWindow()) | 185 if (window == SelectionWindow()) |
| 144 window_label_view_->SetText(window->title()); | 186 window_label_view_->SetText(window->title()); |
| 145 } | 187 } |
| 146 | 188 |
| 147 void WindowSelectorItem::UpdateCloseButtonBounds(aura::Window* root_window, | 189 void WindowSelectorItem::UpdateCloseButtonBounds(aura::Window* root_window, |
| 148 bool animate) { | 190 bool animate) { |
| 149 gfx::RectF align_bounds(SelectionWindow()->layer()->bounds()); | 191 gfx::RectF align_bounds(SelectionWindow()->layer()->bounds()); |
| 150 gfx::Transform window_transform; | 192 gfx::Transform window_transform; |
| 151 window_transform.Translate(align_bounds.x(), align_bounds.y()); | 193 window_transform.Translate(align_bounds.x(), align_bounds.y()); |
| 152 window_transform.PreconcatTransform(SelectionWindow()->layer()-> | 194 window_transform.PreconcatTransform(SelectionWindow()->layer()-> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 242 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 201 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 243 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 202 ScopedTransformOverviewWindow::kTransitionMilliseconds)); | 244 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
| 203 close_button_->GetNativeWindow()->SetTransform(close_button_transform); | 245 close_button_->GetNativeWindow()->SetTransform(close_button_transform); |
| 204 } else { | 246 } else { |
| 205 close_button_->GetNativeWindow()->SetTransform(close_button_transform); | 247 close_button_->GetNativeWindow()->SetTransform(close_button_transform); |
| 206 } | 248 } |
| 207 } | 249 } |
| 208 } | 250 } |
| 209 | 251 |
| 252 void WindowSelectorItem::SetOpacity(float opacity) { | |
| 253 window_label_->GetNativeWindow()->layer()->SetOpacity(opacity); | |
| 254 close_button_->GetNativeWindow()->layer()->SetOpacity(opacity); | |
| 255 } | |
| 256 | |
| 210 void WindowSelectorItem::UpdateWindowLabels(const gfx::Rect& window_bounds, | 257 void WindowSelectorItem::UpdateWindowLabels(const gfx::Rect& window_bounds, |
| 211 aura::Window* root_window, | 258 aura::Window* root_window, |
| 212 bool animate) { | 259 bool animate) { |
| 213 gfx::Rect converted_bounds = ScreenUtil::ConvertRectFromScreen(root_window, | 260 gfx::Rect converted_bounds = ScreenUtil::ConvertRectFromScreen(root_window, |
| 214 window_bounds); | 261 window_bounds); |
| 215 gfx::Rect label_bounds(converted_bounds.x(), | 262 gfx::Rect label_bounds(converted_bounds.x(), |
| 216 converted_bounds.bottom(), | 263 converted_bounds.bottom(), |
| 217 converted_bounds.width(), | 264 converted_bounds.width(), |
| 218 0); | 265 0); |
| 219 | 266 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, | 336 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, |
| 290 0, | 337 0, |
| 291 kVerticalLabelPadding, | 338 kVerticalLabelPadding, |
| 292 0); | 339 0); |
| 293 window_label_view_->SetLayoutManager(layout); | 340 window_label_view_->SetLayoutManager(layout); |
| 294 window_label_->SetContentsView(window_label_view_); | 341 window_label_->SetContentsView(window_label_view_); |
| 295 window_label_->Show(); | 342 window_label_->Show(); |
| 296 } | 343 } |
| 297 | 344 |
| 298 } // namespace ash | 345 } // namespace ash |
| OLD | NEW |