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_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/controls/label.h" | |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 | 19 |
| 19 namespace ash { | 20 namespace ash { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 24 // Foreground label color. Right now it's white | |
| 25 static const int kLabelColor = 0xFFFFFFFF; | |
|
flackr
2014/04/10 15:03:05
Use SK_ColorWHITE, the type should be SkColor
| |
| 26 | |
| 27 // Background label color. Right now it's black. | |
| 28 static const int kLabelBackground = 0x000000; | |
|
flackr
2014/04/10 15:03:05
Ditto, use SkColor type and color constant SK_Colo
| |
| 29 | |
| 30 views::Widget* CreateWindowLabel(aura::Window* root_window, | |
| 31 const base::string16 title) { | |
| 32 views::Widget* widget = new views::Widget; | |
| 33 views::Widget::InitParams params; | |
| 34 params.type = views::Widget::InitParams::TYPE_POPUP; | |
| 35 params.can_activate = false; | |
| 36 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 37 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | |
| 38 params.parent = | |
| 39 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | |
| 40 widget->set_focus_on_creation(false); | |
| 41 widget->Init(params); | |
| 42 views::Label* label = new views::Label; | |
| 43 label->SetEnabledColor(kLabelColor); | |
| 44 label->SetBackgroundColor(kLabelBackground); | |
| 45 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 46 label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); | |
| 47 label->SetText(title); | |
| 48 widget->SetContentsView(label); | |
| 49 widget->Show(); | |
| 50 return widget; | |
| 51 } | |
| 52 | |
| 23 views::Widget* CreateCloseWindowButton(aura::Window* root_window, | 53 views::Widget* CreateCloseWindowButton(aura::Window* root_window, |
| 24 views::ButtonListener* listener) { | 54 views::ButtonListener* listener) { |
| 25 views::Widget* widget = new views::Widget; | 55 views::Widget* widget = new views::Widget; |
| 26 views::Widget::InitParams params; | 56 views::Widget::InitParams params; |
| 27 params.type = views::Widget::InitParams::TYPE_POPUP; | 57 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 28 params.can_activate = false; | 58 params.can_activate = false; |
| 29 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 59 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 30 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 60 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 31 params.parent = | 61 params.parent = |
| 32 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | 62 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 } | 125 } |
| 96 | 126 |
| 97 void WindowSelectorWindow::PrepareForOverview() { | 127 void WindowSelectorWindow::PrepareForOverview() { |
| 98 transform_window_.PrepareForOverview(); | 128 transform_window_.PrepareForOverview(); |
| 99 } | 129 } |
| 100 | 130 |
| 101 void WindowSelectorWindow::SetItemBounds(aura::Window* root_window, | 131 void WindowSelectorWindow::SetItemBounds(aura::Window* root_window, |
| 102 const gfx::Rect& target_bounds, | 132 const gfx::Rect& target_bounds, |
| 103 bool animate) { | 133 bool animate) { |
| 104 gfx::Rect src_rect = transform_window_.GetBoundsInScreen(); | 134 gfx::Rect src_rect = transform_window_.GetBoundsInScreen(); |
| 105 set_bounds(ScopedTransformOverviewWindow:: | 135 const gfx::Rect window_bounds = |
| 106 ShrinkRectToFitPreservingAspectRatio(src_rect, target_bounds)); | 136 ScopedTransformOverviewWindow:: |
| 137 ShrinkRectToFitPreservingAspectRatio(src_rect, target_bounds); | |
| 138 set_bounds(window_bounds); | |
| 107 transform_window_.SetTransform(root_window, | 139 transform_window_.SetTransform(root_window, |
| 108 ScopedTransformOverviewWindow::GetTransformForRect(src_rect, bounds()), | 140 ScopedTransformOverviewWindow::GetTransformForRect(src_rect, bounds()), |
| 109 animate); | 141 animate); |
| 142 UpdateWindowLabels(window_bounds); | |
| 110 UpdateCloseButtonBounds(); | 143 UpdateCloseButtonBounds(); |
| 111 } | 144 } |
| 112 | 145 |
| 113 void WindowSelectorWindow::ButtonPressed(views::Button* sender, | 146 void WindowSelectorWindow::ButtonPressed(views::Button* sender, |
| 114 const ui::Event& event) { | 147 const ui::Event& event) { |
| 115 views::Widget::GetTopLevelWidgetForNativeView( | 148 views::Widget::GetTopLevelWidgetForNativeView( |
| 116 transform_window_.window())->Close(); | 149 transform_window_.window())->Close(); |
| 117 } | 150 } |
| 118 | 151 |
| 152 void WindowSelectorWindow::UpdateWindowLabels(const gfx::Rect& window_bounds) { | |
| 153 // TODO Animate the labels with some cute effects | |
|
flackr
2014/04/10 15:03:05
TODO(nsatragno). That being said, given everything
| |
| 154 base::string16 window_title = transform_window_.window()->title(); | |
|
flackr
2014/04/10 15:03:05
nit, move this to the scope where it's used, i.e.
| |
| 155 if (!window_label_) | |
| 156 window_label_.reset(CreateWindowLabel(GetRootWindow(), window_title)); | |
| 157 // TODO use constant for box height? Calculate dynamically? | |
|
flackr
2014/04/10 15:03:05
Seems like it already uses a constant. That being
| |
| 158 gfx::Rect label_bounds(window_bounds.x(), | |
| 159 window_bounds.y() + window_bounds.height(), | |
| 160 window_bounds.width(), | |
| 161 40); | |
|
flackr
2014/04/10 15:03:05
nit: this height should be defined as a constant.
| |
| 162 window_label_->GetNativeWindow()->SetBounds(label_bounds); | |
| 163 } | |
| 164 | |
| 119 void WindowSelectorWindow::UpdateCloseButtonBounds() { | 165 void WindowSelectorWindow::UpdateCloseButtonBounds() { |
| 120 aura::Window* root_window = GetRootWindow(); | 166 aura::Window* root_window = GetRootWindow(); |
| 121 gfx::Rect align_bounds(bounds()); | 167 gfx::Rect align_bounds(bounds()); |
| 122 gfx::Transform close_button_transform; | 168 gfx::Transform close_button_transform; |
| 123 close_button_transform.Translate(align_bounds.right(), align_bounds.y()); | 169 close_button_transform.Translate(align_bounds.right(), align_bounds.y()); |
| 124 | 170 |
| 125 // If the root window has changed, force the close button to be recreated | 171 // If the root window has changed, force the close button to be recreated |
| 126 // and faded in on the new root window. | 172 // and faded in on the new root window. |
| 127 if (close_button_ && | 173 if (close_button_ && |
| 128 close_button_->GetNativeWindow()->GetRootWindow() != root_window) { | 174 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()); | 207 close_button_->GetNativeWindow()->layer()->GetAnimator()); |
| 162 settings.SetPreemptionStrategy( | 208 settings.SetPreemptionStrategy( |
| 163 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 209 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 164 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 210 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 165 ScopedTransformOverviewWindow::kTransitionMilliseconds)); | 211 ScopedTransformOverviewWindow::kTransitionMilliseconds)); |
| 166 close_button_->GetNativeWindow()->SetTransform(close_button_transform); | 212 close_button_->GetNativeWindow()->SetTransform(close_button_transform); |
| 167 } | 213 } |
| 168 } | 214 } |
| 169 | 215 |
| 170 } // namespace ash | 216 } // namespace ash |
| OLD | NEW |