Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / shelf / shelf_widget.cc
index fb40d5e..73bbeaa 100644 (file)
@@ -7,7 +7,7 @@
 #include "ash/ash_switches.h"
 #include "ash/focus_cycler.h"
 #include "ash/root_window_controller.h"
-#include "ash/session_state_delegate.h"
+#include "ash/session/session_state_delegate.h"
 #include "ash/shelf/shelf_constants.h"
 #include "ash/shelf/shelf_delegate.h"
 #include "ash/shelf/shelf_layout_manager.h"
@@ -22,9 +22,8 @@
 #include "ash/wm/window_properties.h"
 #include "ash/wm/workspace_controller.h"
 #include "grit/ash_resources.h"
-#include "ui/aura/client/activation_client.h"
-#include "ui/aura/root_window.h"
 #include "ui/aura/window.h"
+#include "ui/aura/window_event_dispatcher.h"
 #include "ui/aura/window_observer.h"
 #include "ui/base/resource/resource_bundle.h"
 #include "ui/compositor/layer.h"
@@ -37,7 +36,8 @@
 #include "ui/views/accessible_pane_view.h"
 #include "ui/views/widget/widget.h"
 #include "ui/views/widget/widget_delegate.h"
-#include "ui/wm/public/easy_resize_window_targeter.h"
+#include "ui/wm/core/easy_resize_window_targeter.h"
+#include "ui/wm/public/activation_client.h"
 
 namespace {
 // Size of black border at bottom (or side) of shelf.
@@ -52,13 +52,13 @@ const int kTimeToUnDimMs = 200;  // Fast in activating.
 // Class used to slightly dim shelf items when maximized and visible.
 class DimmerView : public views::View,
                    public views::WidgetDelegate,
-                   ash::internal::BackgroundAnimatorDelegate {
+                   ash::BackgroundAnimatorDelegate {
  public:
   // If |disable_dimming_animations_for_test| is set, all alpha animations will
   // be performed instantly.
   DimmerView(ash::ShelfWidget* shelf_widget,
              bool disable_dimming_animations_for_test);
-  virtual ~DimmerView();
+  ~DimmerView() override;
 
   // Called by |DimmerEventFilter| when the mouse |hovered| state changes.
   void SetHovered(bool hovered);
@@ -67,21 +67,17 @@ class DimmerView : public views::View,
   void ForceUndimming(bool force);
 
   // views::WidgetDelegate overrides:
-  virtual views::Widget* GetWidget() OVERRIDE {
-    return View::GetWidget();
-  }
-  virtual const views::Widget* GetWidget() const OVERRIDE {
-    return View::GetWidget();
-  }
+  views::Widget* GetWidget() override { return View::GetWidget(); }
+  const views::Widget* GetWidget() const override { return View::GetWidget(); }
 
-  // ash::internal::BackgroundAnimatorDelegate overrides:
-  virtual void UpdateBackground(int alpha) OVERRIDE {
+  // ash::BackgroundAnimatorDelegate overrides:
+  void UpdateBackground(int alpha) override {
     alpha_ = alpha;
     SchedulePaint();
   }
 
   // views::View overrides:
-  virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
+  void OnPaintBackground(gfx::Canvas* canvas) override;
 
   // A function to test the current alpha used.
   int get_dimming_alpha_for_test() { return alpha_; }
@@ -91,11 +87,11 @@ class DimmerView : public views::View,
   class DimmerEventFilter : public ui::EventHandler {
    public:
     explicit DimmerEventFilter(DimmerView* owner);
-    virtual ~DimmerEventFilter();
+    ~DimmerEventFilter() override;
 
     // Overridden from ui::EventHandler:
-    virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
-    virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
+    void OnMouseEvent(ui::MouseEvent* event) override;
+    void OnTouchEvent(ui::TouchEvent* event) override;
 
    private:
     // The owning class.
@@ -126,7 +122,7 @@ class DimmerView : public views::View,
   bool disable_dimming_animations_for_test_;
 
   // The animator for the background transitions.
-  ash::internal::BackgroundAnimator background_animator_;
+  ash::BackgroundAnimator background_animator_;
 
   // Notification of entering / exiting of the shelf area by mouse.
   scoped_ptr<DimmerEventFilter> event_filter_;
@@ -175,9 +171,9 @@ void DimmerView::ForceUndimming(bool force) {
 
 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) {
   SkPaint paint;
-  ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+  ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
   gfx::ImageSkia shelf_background =
-      *rb.GetImageNamed(IDR_AURA_LAUNCHER_DIMMING).ToImageSkia();
+      *rb.GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia();
 
   if (shelf_->GetAlignment() != ash::SHELF_ALIGNMENT_BOTTOM) {
     shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
@@ -234,7 +230,7 @@ void DimmerView::DimmerEventFilter::OnTouchEvent(ui::TouchEvent* event) {
   touch_inside_ = touch_inside;
 }
 
-using ash::internal::ShelfLayoutManager;
+using ash::ShelfLayoutManager;
 
 // ShelfWindowTargeter makes it easier to resize windows with the mouse when the
 // window-edge slightly overlaps with the shelf edge. The targeter also makes it
@@ -250,7 +246,7 @@ class ShelfWindowTargeter : public wm::EasyResizeWindowTargeter,
     shelf_->AddObserver(this);
   }
 
-  virtual ~ShelfWindowTargeter() {
+  ~ShelfWindowTargeter() override {
     // |shelf_| may have been destroyed by this time.
     if (shelf_)
       shelf_->RemoveObserver(this);
@@ -274,12 +270,9 @@ class ShelfWindowTargeter : public wm::EasyResizeWindowTargeter,
   }
 
   // ash::ShelfLayoutManagerObserver:
-  virtual void WillDeleteShelf() OVERRIDE {
-    shelf_ = NULL;
-  }
+  void WillDeleteShelf() override { shelf_ = NULL; }
 
-  virtual void WillChangeVisibilityState(
-      ash::ShelfVisibilityState new_state) OVERRIDE {
+  void WillChangeVisibilityState(ash::ShelfVisibilityState new_state) override {
     gfx::Insets mouse_insets;
     gfx::Insets touch_insets;
     if (new_state == ash::SHELF_VISIBLE) {
@@ -313,20 +306,19 @@ namespace ash {
 // sizes it to the width of the shelf minus the size of the status area.
 class ShelfWidget::DelegateView : public views::WidgetDelegate,
                                   public views::AccessiblePaneView,
-                                  public internal::BackgroundAnimatorDelegate,
+                                  public BackgroundAnimatorDelegate,
                                   public aura::WindowObserver {
  public:
   explicit DelegateView(ShelfWidget* shelf);
-  virtual ~DelegateView();
+  ~DelegateView() override;
 
-  void set_focus_cycler(internal::FocusCycler* focus_cycler) {
+  void set_focus_cycler(FocusCycler* focus_cycler) {
     focus_cycler_ = focus_cycler;
   }
-  internal::FocusCycler* focus_cycler() {
-    return focus_cycler_;
-  }
+  FocusCycler* focus_cycler() { return focus_cycler_; }
 
   ui::Layer* opaque_background() { return &opaque_background_; }
+  ui::Layer* opaque_foreground() { return &opaque_foreground_; }
 
   // Set if the shelf area is dimmed (eg when a window is maximized).
   void SetDimmed(bool dimmed);
@@ -335,33 +327,29 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
   void SetParentLayer(ui::Layer* layer);
 
   // views::View overrides:
-  virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
+  void OnPaintBackground(gfx::Canvas* canvas) override;
 
   // views::WidgetDelegateView overrides:
-  virtual views::Widget* GetWidget() OVERRIDE {
-    return View::GetWidget();
-  }
-  virtual const views::Widget* GetWidget() const OVERRIDE {
-    return View::GetWidget();
-  }
+  views::Widget* GetWidget() override { return View::GetWidget(); }
+  const views::Widget* GetWidget() const override { return View::GetWidget(); }
 
-  virtual bool CanActivate() const OVERRIDE;
-  virtual void Layout() OVERRIDE;
-  virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE;
+  bool CanActivate() const override;
+  void Layout() override;
+  void ReorderChildLayers(ui::Layer* parent_layer) override;
   // This will be called when the parent local bounds change.
-  virtual void OnBoundsChanged(const gfx::Rect& old_bounds) OVERRIDE;
+  void OnBoundsChanged(const gfx::Rect& old_bounds) override;
 
   // aura::WindowObserver overrides:
   // This will be called when the shelf itself changes its absolute position.
   // Since the |dimmer_| panel needs to be placed in screen coordinates it needs
   // to be repositioned. The difference to the OnBoundsChanged call above is
   // that this gets also triggered when the shelf only moves.
-  virtual void OnWindowBoundsChanged(aura::Window* window,
-                                     const gfx::Rect& old_bounds,
-                                     const gfx::Rect& new_bounds) OVERRIDE;
+  void OnWindowBoundsChanged(aura::Window* window,
+                             const gfx::Rect& old_bounds,
+                             const gfx::Rect& new_bounds) override;
 
   // BackgroundAnimatorDelegate overrides:
-  virtual void UpdateBackground(int alpha) OVERRIDE;
+  void UpdateBackground(int alpha) override;
 
   // Force the shelf to be presented in an undimmed state.
   void ForceUndimming(bool force);
@@ -383,9 +371,14 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
  private:
   ShelfWidget* shelf_;
   scoped_ptr<views::Widget> dimmer_;
-  internal::FocusCycler* focus_cycler_;
+  FocusCycler* focus_cycler_;
   int alpha_;
+  // A black background layer which is shown when a maximized window is visible.
   ui::Layer opaque_background_;
+  // A black foreground layer which is shown while transitioning between users.
+  // Note: Since the back- and foreground layers have different functions they
+  // can be used simultaneously - so no repurposing possible.
+  ui::Layer opaque_foreground_;
 
   // The view which does the dimming.
   DimmerView* dimmer_view_;
@@ -401,12 +394,16 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf)
       focus_cycler_(NULL),
       alpha_(0),
       opaque_background_(ui::LAYER_SOLID_COLOR),
+      opaque_foreground_(ui::LAYER_SOLID_COLOR),
       dimmer_view_(NULL),
       disable_dimming_animations_for_test_(false) {
   set_allow_deactivate_on_esc(true);
   opaque_background_.SetColor(SK_ColorBLACK);
   opaque_background_.SetBounds(GetLocalBounds());
   opaque_background_.SetOpacity(0.0f);
+  opaque_foreground_.SetColor(SK_ColorBLACK);
+  opaque_foreground_.SetBounds(GetLocalBounds());
+  opaque_foreground_.SetOpacity(0.0f);
 }
 
 ShelfWidget::DelegateView::~DelegateView() {
@@ -423,7 +420,7 @@ void ShelfWidget::DelegateView::SetDimmed(bool value) {
     views::Widget::InitParams params(
         views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
     params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
-    params.can_activate = false;
+    params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
     params.accept_events = false;
     params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
     params.parent = shelf_->GetNativeView();
@@ -452,13 +449,14 @@ bool ShelfWidget::DelegateView::GetDimmed() const {
 
 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) {
   layer->Add(&opaque_background_);
+  layer->Add(&opaque_foreground_);
   ReorderLayers();
 }
 
 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
-  ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+  ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
   gfx::ImageSkia shelf_background =
-      *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND);
+      *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
   if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment())
     shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
         shelf_background,
@@ -491,8 +489,7 @@ void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
     // The part of the shelf background that is in the corner below the docked
     // windows close to the work area is an arched gradient that blends
     // vertically oriented docked background and horizontal shelf.
-    gfx::ImageSkia shelf_corner =
-        *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_CORNER);
+    gfx::ImageSkia shelf_corner = *rb.GetImageSkiaNamed(IDR_ASH_SHELF_CORNER);
     if (dock_bounds.x() == 0) {
       shelf_corner = gfx::ImageSkiaOperations::CreateRotatedImage(
           shelf_corner, SkBitmapOperations::ROTATION_90_CW);
@@ -559,10 +556,12 @@ void ShelfWidget::DelegateView::Layout() {
 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) {
   views::View::ReorderChildLayers(parent_layer);
   parent_layer->StackAtBottom(&opaque_background_);
+  parent_layer->StackAtTop(&opaque_foreground_);
 }
 
 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) {
   opaque_background_.SetBounds(GetLocalBounds());
+  opaque_foreground_.SetBounds(GetLocalBounds());
   if (dimmer_)
     dimmer_->SetBounds(GetBoundsInScreen());
 }
@@ -601,7 +600,7 @@ void ShelfWidget::DelegateView::UpdateBackground(int alpha) {
 
 ShelfWidget::ShelfWidget(aura::Window* shelf_container,
                          aura::Window* status_container,
-                         internal::WorkspaceController* workspace_controller)
+                         WorkspaceController* workspace_controller)
     : delegate_view_(new DelegateView(this)),
       background_animator_(delegate_view_, 0, kShelfBackgroundAlpha),
       activating_as_fallback_(false),
@@ -619,7 +618,7 @@ ShelfWidget::ShelfWidget(aura::Window* shelf_container,
   SetContentsView(delegate_view_);
   delegate_view_->SetParentLayer(GetLayer());
 
-  status_area_widget_ = new internal::StatusAreaWidget(status_container);
+  status_area_widget_ = new StatusAreaWidget(status_container);
   status_area_widget_->CreateTrayViews();
   if (Shell::GetInstance()->session_state_delegate()->
           IsActiveUserSessionStarted()) {
@@ -627,14 +626,14 @@ ShelfWidget::ShelfWidget(aura::Window* shelf_container,
   }
   Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_);
 
-  shelf_layout_manager_ = new internal::ShelfLayoutManager(this);
+  shelf_layout_manager_ = new ShelfLayoutManager(this);
   shelf_layout_manager_->AddObserver(this);
   shelf_container->SetLayoutManager(shelf_layout_manager_);
   shelf_layout_manager_->set_workspace_controller(workspace_controller);
   workspace_controller->SetShelf(shelf_layout_manager_);
 
   status_container->SetLayoutManager(
-      new internal::StatusAreaLayoutManager(this));
+      new StatusAreaLayoutManager(status_container, this));
 
   shelf_container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(new
       ShelfWindowTargeter(shelf_container, shelf_layout_manager_)));
@@ -681,10 +680,32 @@ ShelfBackgroundType ShelfWidget::GetBackgroundType() const {
   return SHELF_BACKGROUND_DEFAULT;
 }
 
+void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) {
+  if (IsShelfHiddenBehindBlackBar() == hide)
+    return;
+
+  ui::Layer* opaque_foreground = delegate_view_->opaque_foreground();
+  float target_opacity = hide ? 1.0f : 0.0f;
+  scoped_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation;
+  opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings(
+      opaque_foreground->GetAnimator()));
+  opaque_foreground_animation->SetTransitionDuration(
+      base::TimeDelta::FromMilliseconds(animation_time_ms));
+  opaque_foreground_animation->SetPreemptionStrategy(
+      ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
+
+  opaque_foreground->SetOpacity(target_opacity);
+}
+
+bool ShelfWidget::IsShelfHiddenBehindBlackBar() const {
+  return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f;
+}
+
 // static
 bool ShelfWidget::ShelfAlignmentAllowed() {
-  if (!ash::switches::ShowShelfAlignmentMenu())
+  if (Shell::GetInstance()->system_tray_delegate()->IsUserSupervised())
     return false;
+
   user::LoginStatus login_status =
       Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
 
@@ -694,7 +715,7 @@ bool ShelfWidget::ShelfAlignmentAllowed() {
       return true;
     case user::LOGGED_IN_LOCKED:
     case user::LOGGED_IN_PUBLIC:
-    case user::LOGGED_IN_LOCALLY_MANAGED:
+    case user::LOGGED_IN_SUPERVISED:
     case user::LOGGED_IN_GUEST:
     case user::LOGGED_IN_RETAIL_MODE:
     case user::LOGGED_IN_KIOSK_APP:
@@ -723,7 +744,7 @@ void ShelfWidget::SetDimsShelf(bool dimming) {
   // status area background, app list button and overflow button.
   if (shelf_)
     shelf_->SchedulePaint();
-  status_area_widget_->GetContentsView()->SchedulePaint();
+  status_area_widget_->SchedulePaint();
 }
 
 bool ShelfWidget::GetDimsShelf() const {
@@ -745,8 +766,7 @@ void ShelfWidget::CreateShelf() {
   SetFocusCycler(shell->focus_cycler());
 
   // Inform the root window controller.
-  internal::RootWindowController::ForWindow(window_container_)
-      ->OnShelfCreated();
+  RootWindowController::ForWindow(window_container_)->OnShelfCreated();
 
   shelf_->SetVisible(
       shell->session_state_delegate()->IsActiveUserSessionStarted());
@@ -763,13 +783,13 @@ void ShelfWidget::SetShelfVisibility(bool visible) {
     shelf_->SetVisible(visible);
 }
 
-void ShelfWidget::SetFocusCycler(internal::FocusCycler* focus_cycler) {
+void ShelfWidget::SetFocusCycler(FocusCycler* focus_cycler) {
   delegate_view_->set_focus_cycler(focus_cycler);
   if (focus_cycler)
     focus_cycler->AddWidget(this);
 }
 
-internal::FocusCycler* ShelfWidget::GetFocusCycler() {
+FocusCycler* ShelfWidget::GetFocusCycler() {
   return delegate_view_->focus_cycler();
 }