Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / wm / overview / window_selector_window.cc
index 40b53d4..548026d 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "ash/wm/overview/window_selector_window.h"
 
+#include "ash/screen_util.h"
 #include "ash/shell.h"
 #include "ash/shell_window_ids.h"
 #include "ash/wm/overview/scoped_transform_overview_window.h"
@@ -28,8 +29,8 @@ views::Widget* CreateCloseWindowButton(aura::Window* root_window,
   params.can_activate = false;
   params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
   params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
-  params.parent = Shell::GetContainer(root_window,
-      ash::internal::kShellWindowId_OverlayContainer);
+  params.parent =
+      Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer);
   widget->set_focus_on_creation(false);
   widget->Init(params);
   views::ImageButton* button = new views::ImageButton(listener);
@@ -46,10 +47,6 @@ views::Widget* CreateCloseWindowButton(aura::Window* root_window,
   return widget;
 }
 
-// The time for the close button to fade in when initially shown on entering
-// overview mode.
-const int kCloseButtonFadeInMilliseconds = 80;
-
 }  // namespace
 
 WindowSelectorWindow::WindowSelectorWindow(aura::Window* window)
@@ -103,11 +100,14 @@ void WindowSelectorWindow::SetItemBounds(aura::Window* root_window,
                                          bool animate) {
   gfx::Rect src_rect = transform_window_.GetBoundsInScreen();
   set_bounds(ScopedTransformOverviewWindow::
-      ShrinkRectToFitPreservingAspectRatio(src_rect, target_bounds));
+        ShrinkRectToFitPreservingAspectRatio(src_rect, target_bounds));
   transform_window_.SetTransform(root_window,
       ScopedTransformOverviewWindow::GetTransformForRect(src_rect, bounds()),
       animate);
-  UpdateCloseButtonBounds();
+  // TODO move close button management to WindowSelectorItem, so that we can
+  // also handle panels.
+  // See http://crbug.com/352143
+  UpdateCloseButtonBounds(root_window, animate);
 }
 
 void WindowSelectorWindow::ButtonPressed(views::Button* sender,
@@ -116,9 +116,10 @@ void WindowSelectorWindow::ButtonPressed(views::Button* sender,
       transform_window_.window())->Close();
 }
 
-void WindowSelectorWindow::UpdateCloseButtonBounds() {
-  aura::Window* root_window = GetRootWindow();
-  gfx::Rect align_bounds(bounds());
+void WindowSelectorWindow::UpdateCloseButtonBounds(aura::Window* root_window,
+                                                   bool animate) {
+  gfx::Rect align_bounds(
+      ScreenUtil::ConvertRectFromScreen(root_window, bounds()));
   gfx::Transform close_button_transform;
   close_button_transform.Translate(align_bounds.right(), align_bounds.y());
 
@@ -153,17 +154,21 @@ void WindowSelectorWindow::UpdateCloseButtonBounds() {
       settings.SetPreemptionStrategy(
           ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
       settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
-            kCloseButtonFadeInMilliseconds));
+            WindowSelectorItem::kFadeInMilliseconds));
       layer->SetOpacity(1);
     }
   } else {
-    ui::ScopedLayerAnimationSettings settings(
-        close_button_->GetNativeWindow()->layer()->GetAnimator());
-    settings.SetPreemptionStrategy(
-        ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
-    settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
-        ScopedTransformOverviewWindow::kTransitionMilliseconds));
-    close_button_->GetNativeWindow()->SetTransform(close_button_transform);
+    if (animate) {
+      ui::ScopedLayerAnimationSettings settings(
+          close_button_->GetNativeWindow()->layer()->GetAnimator());
+      settings.SetPreemptionStrategy(
+          ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+      settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
+          ScopedTransformOverviewWindow::kTransitionMilliseconds));
+      close_button_->GetNativeWindow()->SetTransform(close_button_transform);
+    } else {
+      close_button_->GetNativeWindow()->SetTransform(close_button_transform);
+    }
   }
 }