| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/shelf/shelf_widget.h" | 5 #include "ash/shelf/shelf_widget.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_shelf_aura.h" | 7 #include "ash/aura/wm_shelf_aura.h" |
| 8 #include "ash/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
| 9 #include "ash/common/ash_switches.h" | |
| 10 #include "ash/common/focus_cycler.h" | 9 #include "ash/common/focus_cycler.h" |
| 11 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| 12 #include "ash/common/session/session_state_delegate.h" | 11 #include "ash/common/session/session_state_delegate.h" |
| 13 #include "ash/common/shelf/shelf_background_animator_observer.h" | 12 #include "ash/common/shelf/shelf_background_animator_observer.h" |
| 14 #include "ash/common/shelf/shelf_constants.h" | 13 #include "ash/common/shelf/shelf_constants.h" |
| 15 #include "ash/common/shelf/shelf_delegate.h" | 14 #include "ash/common/shelf/shelf_delegate.h" |
| 16 #include "ash/common/shelf/shelf_model.h" | |
| 17 #include "ash/common/shelf/wm_shelf.h" | 15 #include "ash/common/shelf/wm_shelf.h" |
| 18 #include "ash/common/shelf/wm_shelf_util.h" | 16 #include "ash/common/shelf/wm_shelf_util.h" |
| 19 #include "ash/common/shell_window_ids.h" | |
| 20 #include "ash/common/system/status_area_widget.h" | 17 #include "ash/common/system/status_area_widget.h" |
| 21 #include "ash/common/system/tray/system_tray_delegate.h" | 18 #include "ash/common/system/tray/system_tray_delegate.h" |
| 22 #include "ash/common/wm_root_window_controller.h" | 19 #include "ash/common/wm_root_window_controller.h" |
| 23 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 21 #include "ash/shelf/dimmer_view.h" |
| 24 #include "ash/shelf/shelf.h" | 22 #include "ash/shelf/shelf.h" |
| 25 #include "ash/shelf/shelf_layout_manager.h" | 23 #include "ash/shelf/shelf_layout_manager.h" |
| 26 #include "ash/shelf/shelf_util.h" | |
| 27 #include "ash/shelf/shelf_view.h" | |
| 28 #include "ash/shell.h" | 24 #include "ash/shell.h" |
| 29 #include "ash/wm/status_area_layout_manager.h" | 25 #include "ash/wm/status_area_layout_manager.h" |
| 30 #include "ash/wm/window_properties.h" | |
| 31 #include "ash/wm/workspace_controller.h" | 26 #include "ash/wm/workspace_controller.h" |
| 32 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
| 33 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
| 34 #include "ui/aura/window_event_dispatcher.h" | |
| 35 #include "ui/aura/window_observer.h" | |
| 36 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
| 38 #include "ui/compositor/scoped_layer_animation_settings.h" | 31 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 39 #include "ui/events/event_constants.h" | |
| 40 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
| 41 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
| 42 #include "ui/gfx/image/image_skia_operations.h" | 34 #include "ui/gfx/image/image_skia_operations.h" |
| 43 #include "ui/gfx/skbitmap_operations.h" | 35 #include "ui/gfx/skbitmap_operations.h" |
| 44 #include "ui/views/accessible_pane_view.h" | 36 #include "ui/views/accessible_pane_view.h" |
| 45 #include "ui/views/layout/fill_layout.h" | 37 #include "ui/views/layout/fill_layout.h" |
| 46 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 47 #include "ui/views/widget/widget_delegate.h" | 39 #include "ui/views/widget/widget_delegate.h" |
| 48 #include "ui/wm/core/coordinate_conversion.h" | |
| 49 #include "ui/wm/core/easy_resize_window_targeter.h" | 40 #include "ui/wm/core/easy_resize_window_targeter.h" |
| 50 #include "ui/wm/public/activation_client.h" | |
| 51 | 41 |
| 52 namespace ash { | 42 namespace ash { |
| 53 | 43 |
| 54 namespace { | 44 namespace { |
| 45 |
| 55 // Size of black border at bottom (or side) of shelf. | 46 // Size of black border at bottom (or side) of shelf. |
| 56 const int kNumBlackPixels = 3; | 47 const int kNumBlackPixels = 3; |
| 57 // Alpha to paint dimming image with. | |
| 58 const int kDimAlpha = 128; | |
| 59 | |
| 60 // The time to dim and un-dim. | |
| 61 const int kTimeToDimMs = 3000; // Slow in dimming. | |
| 62 const int kTimeToUnDimMs = 200; // Fast in activating. | |
| 63 | |
| 64 // Class used to slightly dim shelf items when maximized and visible. | |
| 65 class DimmerView : public views::View, | |
| 66 public views::WidgetDelegate, | |
| 67 BackgroundAnimatorDelegate { | |
| 68 public: | |
| 69 // If |disable_dimming_animations_for_test| is set, all alpha animations will | |
| 70 // be performed instantly. | |
| 71 DimmerView(ShelfWidget* shelf_widget, | |
| 72 bool disable_dimming_animations_for_test); | |
| 73 ~DimmerView() override; | |
| 74 | |
| 75 // Called by |DimmerEventFilter| when the mouse |hovered| state changes. | |
| 76 void SetHovered(bool hovered); | |
| 77 | |
| 78 // Force the dimmer to be undimmed. | |
| 79 void ForceUndimming(bool force); | |
| 80 | |
| 81 // views::WidgetDelegate overrides: | |
| 82 views::Widget* GetWidget() override { return View::GetWidget(); } | |
| 83 const views::Widget* GetWidget() const override { return View::GetWidget(); } | |
| 84 | |
| 85 // BackgroundAnimatorDelegate overrides: | |
| 86 void UpdateBackground(BackgroundAnimator* animator, int alpha) override { | |
| 87 alpha_ = alpha; | |
| 88 SchedulePaint(); | |
| 89 } | |
| 90 | |
| 91 void BackgroundAnimationEnded(BackgroundAnimator* animator) override {} | |
| 92 | |
| 93 // views::View overrides: | |
| 94 void OnPaintBackground(gfx::Canvas* canvas) override; | |
| 95 | |
| 96 // A function to test the current alpha used. | |
| 97 int get_dimming_alpha_for_test() { return alpha_; } | |
| 98 | |
| 99 private: | |
| 100 // This class monitors mouse events to see if it is on top of the shelf. | |
| 101 class DimmerEventFilter : public ui::EventHandler { | |
| 102 public: | |
| 103 explicit DimmerEventFilter(DimmerView* owner); | |
| 104 ~DimmerEventFilter() override; | |
| 105 | |
| 106 // Overridden from ui::EventHandler: | |
| 107 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 108 void OnTouchEvent(ui::TouchEvent* event) override; | |
| 109 | |
| 110 private: | |
| 111 // The owning class. | |
| 112 DimmerView* owner_; | |
| 113 | |
| 114 // TRUE if the mouse is inside the shelf. | |
| 115 bool mouse_inside_; | |
| 116 | |
| 117 // TRUE if a touch event is inside the shelf. | |
| 118 bool touch_inside_; | |
| 119 | |
| 120 DISALLOW_COPY_AND_ASSIGN(DimmerEventFilter); | |
| 121 }; | |
| 122 | |
| 123 // The owning shelf widget. | |
| 124 ShelfWidget* shelf_; | |
| 125 | |
| 126 // The alpha to use for covering the shelf. | |
| 127 int alpha_; | |
| 128 | |
| 129 // True if the event filter claims that we should not be dimmed. | |
| 130 bool is_hovered_; | |
| 131 | |
| 132 // True if someone forces us not to be dimmed (e.g. a menu is open). | |
| 133 bool force_hovered_; | |
| 134 | |
| 135 // True if animations should be suppressed for a test. | |
| 136 bool disable_dimming_animations_for_test_; | |
| 137 | |
| 138 // The animator for the background transitions. | |
| 139 BackgroundAnimator background_animator_; | |
| 140 | |
| 141 // Notification of entering / exiting of the shelf area by mouse. | |
| 142 std::unique_ptr<DimmerEventFilter> event_filter_; | |
| 143 | |
| 144 DISALLOW_COPY_AND_ASSIGN(DimmerView); | |
| 145 }; | |
| 146 | |
| 147 DimmerView::DimmerView(ShelfWidget* shelf_widget, | |
| 148 bool disable_dimming_animations_for_test) | |
| 149 : shelf_(shelf_widget), | |
| 150 alpha_(kDimAlpha), | |
| 151 is_hovered_(false), | |
| 152 force_hovered_(false), | |
| 153 disable_dimming_animations_for_test_(disable_dimming_animations_for_test), | |
| 154 background_animator_(this, 0, kDimAlpha) { | |
| 155 event_filter_.reset(new DimmerEventFilter(this)); | |
| 156 // Make sure it is undimmed at the beginning and then fire off the dimming | |
| 157 // animation. | |
| 158 background_animator_.SetPaintsBackground(false, BACKGROUND_CHANGE_IMMEDIATE); | |
| 159 SetHovered(false); | |
| 160 } | |
| 161 | |
| 162 DimmerView::~DimmerView() {} | |
| 163 | |
| 164 void DimmerView::SetHovered(bool hovered) { | |
| 165 // Remember the hovered state so that we can correct the state once a | |
| 166 // possible force state has disappeared. | |
| 167 is_hovered_ = hovered; | |
| 168 // Undimm also if we were forced to by e.g. an open menu. | |
| 169 hovered |= force_hovered_; | |
| 170 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); | |
| 171 background_animator_.SetPaintsBackground(!hovered, | |
| 172 disable_dimming_animations_for_test_ | |
| 173 ? BACKGROUND_CHANGE_IMMEDIATE | |
| 174 : BACKGROUND_CHANGE_ANIMATE); | |
| 175 } | |
| 176 | |
| 177 void DimmerView::ForceUndimming(bool force) { | |
| 178 bool previous = force_hovered_; | |
| 179 force_hovered_ = force; | |
| 180 // If the forced change does change the result we apply the change. | |
| 181 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) | |
| 182 SetHovered(is_hovered_); | |
| 183 } | |
| 184 | |
| 185 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { | |
| 186 SkPaint paint; | |
| 187 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
| 188 gfx::ImageSkia shelf_background = | |
| 189 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); | |
| 190 | |
| 191 if (!IsHorizontalAlignment(shelf_->GetAlignment())) { | |
| 192 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | |
| 193 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | |
| 194 ? SkBitmapOperations::ROTATION_90_CW | |
| 195 : SkBitmapOperations::ROTATION_270_CW); | |
| 196 } | |
| 197 paint.setAlpha(alpha_); | |
| 198 canvas->DrawImageInt(shelf_background, 0, 0, shelf_background.width(), | |
| 199 shelf_background.height(), 0, 0, width(), height(), | |
| 200 false, paint); | |
| 201 } | |
| 202 | |
| 203 DimmerView::DimmerEventFilter::DimmerEventFilter(DimmerView* owner) | |
| 204 : owner_(owner), mouse_inside_(false), touch_inside_(false) { | |
| 205 Shell::GetInstance()->AddPreTargetHandler(this); | |
| 206 } | |
| 207 | |
| 208 DimmerView::DimmerEventFilter::~DimmerEventFilter() { | |
| 209 Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 210 } | |
| 211 | |
| 212 void DimmerView::DimmerEventFilter::OnMouseEvent(ui::MouseEvent* event) { | |
| 213 if (event->type() != ui::ET_MOUSE_MOVED && | |
| 214 event->type() != ui::ET_MOUSE_DRAGGED) | |
| 215 return; | |
| 216 | |
| 217 gfx::Point screen_point(event->location()); | |
| 218 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()), | |
| 219 &screen_point); | |
| 220 bool inside = owner_->GetBoundsInScreen().Contains(screen_point); | |
| 221 if (mouse_inside_ || touch_inside_ != inside || touch_inside_) | |
| 222 owner_->SetHovered(inside || touch_inside_); | |
| 223 mouse_inside_ = inside; | |
| 224 } | |
| 225 | |
| 226 void DimmerView::DimmerEventFilter::OnTouchEvent(ui::TouchEvent* event) { | |
| 227 bool touch_inside = false; | |
| 228 if (event->type() != ui::ET_TOUCH_RELEASED && | |
| 229 event->type() != ui::ET_TOUCH_CANCELLED) { | |
| 230 gfx::Point screen_point(event->location()); | |
| 231 ::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()), | |
| 232 &screen_point); | |
| 233 touch_inside = owner_->GetBoundsInScreen().Contains(screen_point); | |
| 234 } | |
| 235 | |
| 236 if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside) | |
| 237 owner_->SetHovered(mouse_inside_ || touch_inside); | |
| 238 touch_inside_ = touch_inside; | |
| 239 } | |
| 240 | 48 |
| 241 // ShelfWindowTargeter makes it easier to resize windows with the mouse when the | 49 // ShelfWindowTargeter makes it easier to resize windows with the mouse when the |
| 242 // window-edge slightly overlaps with the shelf edge. The targeter also makes it | 50 // window-edge slightly overlaps with the shelf edge. The targeter also makes it |
| 243 // easier to drag the shelf out with touch while it is hidden. | 51 // easier to drag the shelf out with touch while it is hidden. |
| 244 class ShelfWindowTargeter : public ::wm::EasyResizeWindowTargeter, | 52 class ShelfWindowTargeter : public ::wm::EasyResizeWindowTargeter, |
| 245 public ShelfLayoutManagerObserver { | 53 public ShelfLayoutManagerObserver { |
| 246 public: | 54 public: |
| 247 ShelfWindowTargeter(aura::Window* container, ShelfLayoutManager* shelf) | 55 ShelfWindowTargeter(aura::Window* container, ShelfLayoutManager* shelf) |
| 248 : ::wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()), | 56 : ::wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()), |
| 249 shelf_(shelf) { | 57 shelf_(shelf) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 262 if (alignment == SHELF_ALIGNMENT_LEFT) | 70 if (alignment == SHELF_ALIGNMENT_LEFT) |
| 263 return gfx::Insets(0, 0, 0, distance); | 71 return gfx::Insets(0, 0, 0, distance); |
| 264 if (alignment == SHELF_ALIGNMENT_RIGHT) | 72 if (alignment == SHELF_ALIGNMENT_RIGHT) |
| 265 return gfx::Insets(0, distance, 0, 0); | 73 return gfx::Insets(0, distance, 0, 0); |
| 266 return gfx::Insets(distance, 0, 0, 0); | 74 return gfx::Insets(distance, 0, 0, 0); |
| 267 } | 75 } |
| 268 | 76 |
| 269 // ShelfLayoutManagerObserver: | 77 // ShelfLayoutManagerObserver: |
| 270 void WillDeleteShelfLayoutManager() override { | 78 void WillDeleteShelfLayoutManager() override { |
| 271 shelf_->RemoveObserver(this); | 79 shelf_->RemoveObserver(this); |
| 272 shelf_ = NULL; | 80 shelf_ = nullptr; |
| 273 } | 81 } |
| 274 | 82 |
| 275 void WillChangeVisibilityState(ShelfVisibilityState new_state) override { | 83 void WillChangeVisibilityState(ShelfVisibilityState new_state) override { |
| 276 gfx::Insets mouse_insets; | 84 gfx::Insets mouse_insets; |
| 277 gfx::Insets touch_insets; | 85 gfx::Insets touch_insets; |
| 278 if (new_state == SHELF_VISIBLE) { | 86 if (new_state == SHELF_VISIBLE) { |
| 279 // Let clicks at the very top of the shelf through so windows can be | 87 // Let clicks at the very top of the shelf through so windows can be |
| 280 // resized with the bottom-right corner and bottom edge. | 88 // resized with the bottom-right corner and bottom edge. |
| 281 mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset, | 89 mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset, |
| 282 shelf_->GetAlignment()); | 90 shelf_->GetAlignment()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 295 | 103 |
| 296 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); | 104 DISALLOW_COPY_AND_ASSIGN(ShelfWindowTargeter); |
| 297 }; | 105 }; |
| 298 | 106 |
| 299 } // namespace | 107 } // namespace |
| 300 | 108 |
| 301 // The contents view of the Shelf. This view contains ShelfView and | 109 // The contents view of the Shelf. This view contains ShelfView and |
| 302 // sizes it to the width of the shelf minus the size of the status area. | 110 // sizes it to the width of the shelf minus the size of the status area. |
| 303 class ShelfWidget::DelegateView : public views::WidgetDelegate, | 111 class ShelfWidget::DelegateView : public views::WidgetDelegate, |
| 304 public views::AccessiblePaneView, | 112 public views::AccessiblePaneView, |
| 305 public aura::WindowObserver, | |
| 306 public ShelfBackgroundAnimatorObserver { | 113 public ShelfBackgroundAnimatorObserver { |
| 307 public: | 114 public: |
| 308 explicit DelegateView(ShelfWidget* shelf); | 115 explicit DelegateView(ShelfWidget* shelf); |
| 309 ~DelegateView() override; | 116 ~DelegateView() override; |
| 310 | 117 |
| 311 void set_focus_cycler(FocusCycler* focus_cycler) { | 118 void set_focus_cycler(FocusCycler* focus_cycler) { |
| 312 focus_cycler_ = focus_cycler; | 119 focus_cycler_ = focus_cycler; |
| 313 } | 120 } |
| 314 FocusCycler* focus_cycler() { return focus_cycler_; } | 121 FocusCycler* focus_cycler() { return focus_cycler_; } |
| 315 | 122 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 327 | 134 |
| 328 // views::WidgetDelegateView overrides: | 135 // views::WidgetDelegateView overrides: |
| 329 views::Widget* GetWidget() override { return View::GetWidget(); } | 136 views::Widget* GetWidget() override { return View::GetWidget(); } |
| 330 const views::Widget* GetWidget() const override { return View::GetWidget(); } | 137 const views::Widget* GetWidget() const override { return View::GetWidget(); } |
| 331 | 138 |
| 332 bool CanActivate() const override; | 139 bool CanActivate() const override; |
| 333 void ReorderChildLayers(ui::Layer* parent_layer) override; | 140 void ReorderChildLayers(ui::Layer* parent_layer) override; |
| 334 // This will be called when the parent local bounds change. | 141 // This will be called when the parent local bounds change. |
| 335 void OnBoundsChanged(const gfx::Rect& old_bounds) override; | 142 void OnBoundsChanged(const gfx::Rect& old_bounds) override; |
| 336 | 143 |
| 337 // aura::WindowObserver overrides: | |
| 338 // This will be called when the shelf itself changes its absolute position. | |
| 339 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs | |
| 340 // to be repositioned. The difference to the OnBoundsChanged call above is | |
| 341 // that this gets also triggered when the shelf only moves. | |
| 342 void OnWindowBoundsChanged(aura::Window* window, | |
| 343 const gfx::Rect& old_bounds, | |
| 344 const gfx::Rect& new_bounds) override; | |
| 345 | |
| 346 // ShelfBackgroundAnimatorObserver: | 144 // ShelfBackgroundAnimatorObserver: |
| 347 void UpdateShelfOpaqueBackground(int alpha) override; | 145 void UpdateShelfOpaqueBackground(int alpha) override; |
| 348 void UpdateShelfAssetBackground(int alpha) override; | 146 void UpdateShelfAssetBackground(int alpha) override; |
| 349 | 147 |
| 350 // Force the shelf to be presented in an undimmed state. | 148 // Force the shelf to be presented in an undimmed state. |
| 351 void ForceUndimming(bool force); | 149 void ForceUndimming(bool force); |
| 352 | 150 |
| 353 // A function to test the current alpha used by the dimming bar. If there is | 151 // A function to test the current alpha used by the dimming bar. If there is |
| 354 // no dimmer active, the function will return -1. | 152 // no dimmer active, the function will return -1. |
| 355 int GetDimmingAlphaForTest(); | 153 int GetDimmingAlphaForTest(); |
| 356 | 154 |
| 357 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if | 155 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if |
| 358 // the dimmer is inactive. | 156 // the dimmer is inactive. |
| 359 gfx::Rect GetDimmerBoundsForTest(); | 157 gfx::Rect GetDimmerBoundsForTest(); |
| 360 | 158 |
| 361 // Disable dimming animations for running tests. This needs to be called | 159 // Disable dimming animations for running tests. This needs to be called |
| 362 // prior to the creation of of the |dimmer_|. | 160 // prior to the creation of of the dimmer. |
| 363 void disable_dimming_animations_for_test() { | 161 void disable_dimming_animations_for_test() { |
| 364 disable_dimming_animations_for_test_ = true; | 162 disable_dimming_animations_for_test_ = true; |
| 365 } | 163 } |
| 366 | 164 |
| 367 private: | 165 private: |
| 368 ShelfWidget* shelf_; | 166 ShelfWidget* shelf_; |
| 369 std::unique_ptr<views::Widget> dimmer_; | |
| 370 FocusCycler* focus_cycler_; | 167 FocusCycler* focus_cycler_; |
| 371 int asset_background_alpha_; | 168 int asset_background_alpha_; |
| 372 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). | 169 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). |
| 373 // A black background layer which is shown when a maximized window is visible. | 170 // A black background layer which is shown when a maximized window is visible. |
| 374 ui::Layer opaque_background_; | 171 ui::Layer opaque_background_; |
| 375 // A black foreground layer which is shown while transitioning between users. | 172 // A black foreground layer which is shown while transitioning between users. |
| 376 // Note: Since the back- and foreground layers have different functions they | 173 // Note: Since the back- and foreground layers have different functions they |
| 377 // can be used simultaneously - so no repurposing possible. | 174 // can be used simultaneously - so no repurposing possible. |
| 378 ui::Layer opaque_foreground_; | 175 ui::Layer opaque_foreground_; |
| 379 | 176 |
| 380 // The view which does the dimming. | 177 // The view which does the dimming. |
| 381 DimmerView* dimmer_view_; | 178 DimmerView* dimmer_view_; |
| 382 | 179 |
| 383 // True if dimming animations should be turned off. | 180 // True if dimming animations should be turned off. |
| 384 bool disable_dimming_animations_for_test_; | 181 bool disable_dimming_animations_for_test_; |
| 385 | 182 |
| 386 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 183 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
| 387 }; | 184 }; |
| 388 | 185 |
| 389 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) | 186 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) |
| 390 : shelf_(shelf), | 187 : shelf_(shelf), |
| 391 focus_cycler_(NULL), | 188 focus_cycler_(nullptr), |
| 392 asset_background_alpha_(0), | 189 asset_background_alpha_(0), |
| 393 opaque_background_(ui::LAYER_SOLID_COLOR), | 190 opaque_background_(ui::LAYER_SOLID_COLOR), |
| 394 opaque_foreground_(ui::LAYER_SOLID_COLOR), | 191 opaque_foreground_(ui::LAYER_SOLID_COLOR), |
| 395 dimmer_view_(NULL), | 192 dimmer_view_(nullptr), |
| 396 disable_dimming_animations_for_test_(false) { | 193 disable_dimming_animations_for_test_(false) { |
| 397 SetLayoutManager(new views::FillLayout()); | 194 SetLayoutManager(new views::FillLayout()); |
| 398 set_allow_deactivate_on_esc(true); | 195 set_allow_deactivate_on_esc(true); |
| 399 opaque_background_.SetColor(SK_ColorBLACK); | 196 opaque_background_.SetColor(SK_ColorBLACK); |
| 400 opaque_background_.SetBounds(GetLocalBounds()); | 197 opaque_background_.SetBounds(GetLocalBounds()); |
| 401 opaque_background_.SetOpacity(0.0f); | 198 opaque_background_.SetOpacity(0.0f); |
| 402 opaque_foreground_.SetColor(SK_ColorBLACK); | 199 opaque_foreground_.SetColor(SK_ColorBLACK); |
| 403 opaque_foreground_.SetBounds(GetLocalBounds()); | 200 opaque_foreground_.SetBounds(GetLocalBounds()); |
| 404 opaque_foreground_.SetOpacity(0.0f); | 201 opaque_foreground_.SetOpacity(0.0f); |
| 405 } | 202 } |
| 406 | 203 |
| 407 ShelfWidget::DelegateView::~DelegateView() { | 204 ShelfWidget::DelegateView::~DelegateView() { |
| 408 // Make sure that the dimmer goes away since it might have set an observer. | 205 // Make sure that the dimmer goes away since it might have set an observer. |
| 409 SetDimmed(false); | 206 SetDimmed(false); |
| 410 } | 207 } |
| 411 | 208 |
| 412 void ShelfWidget::DelegateView::SetDimmed(bool value) { | 209 void ShelfWidget::DelegateView::SetDimmed(bool dimmed) { |
| 413 if (value == (dimmer_.get() != NULL)) | 210 if (dimmed == (dimmer_view_ != nullptr)) |
| 414 return; | 211 return; |
| 415 | 212 |
| 416 if (value) { | 213 if (dimmed) { |
| 417 dimmer_.reset(new views::Widget); | 214 dimmer_view_ = DimmerView::Create(shelf_->wm_shelf_aura_, |
| 418 views::Widget::InitParams params( | 215 disable_dimming_animations_for_test_); |
| 419 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 420 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
| 421 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; | |
| 422 params.accept_events = false; | |
| 423 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 424 params.parent = shelf_->GetNativeView(); | |
| 425 dimmer_->Init(params); | |
| 426 dimmer_->GetNativeWindow()->SetName("ShelfDimmer"); | |
| 427 dimmer_->SetBounds(shelf_->GetWindowBoundsInScreen()); | |
| 428 // The shelf should not take focus when it is initially shown. | |
| 429 dimmer_->set_focus_on_creation(false); | |
| 430 dimmer_view_ = new DimmerView(shelf_, disable_dimming_animations_for_test_); | |
| 431 dimmer_->SetContentsView(dimmer_view_); | |
| 432 dimmer_->GetNativeView()->SetName("ShelfDimmerView"); | |
| 433 dimmer_->Show(); | |
| 434 shelf_->GetNativeView()->AddObserver(this); | |
| 435 } else { | 216 } else { |
| 436 // Some unit tests will come here with a destroyed window. | 217 dimmer_view_->GetWidget()->CloseNow(); |
| 437 if (shelf_->GetNativeView()) | 218 dimmer_view_ = nullptr; |
| 438 shelf_->GetNativeView()->RemoveObserver(this); | |
| 439 dimmer_view_ = NULL; | |
| 440 dimmer_.reset(NULL); | |
| 441 } | 219 } |
| 442 } | 220 } |
| 443 | 221 |
| 444 bool ShelfWidget::DelegateView::GetDimmed() const { | 222 bool ShelfWidget::DelegateView::GetDimmed() const { |
| 445 return dimmer_.get() && dimmer_->IsVisible(); | 223 return dimmer_view_ && dimmer_view_->GetWidget()->IsVisible(); |
| 446 } | 224 } |
| 447 | 225 |
| 448 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { | 226 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
| 449 layer->Add(&opaque_background_); | 227 layer->Add(&opaque_background_); |
| 450 layer->Add(&opaque_foreground_); | 228 layer->Add(&opaque_foreground_); |
| 451 ReorderLayers(); | 229 ReorderLayers(); |
| 452 } | 230 } |
| 453 | 231 |
| 454 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 232 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
| 455 if (MaterialDesignController::IsShelfMaterial()) | 233 if (MaterialDesignController::IsShelfMaterial()) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 298 |
| 521 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { | 299 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { |
| 522 views::View::ReorderChildLayers(parent_layer); | 300 views::View::ReorderChildLayers(parent_layer); |
| 523 parent_layer->StackAtBottom(&opaque_background_); | 301 parent_layer->StackAtBottom(&opaque_background_); |
| 524 parent_layer->StackAtTop(&opaque_foreground_); | 302 parent_layer->StackAtTop(&opaque_foreground_); |
| 525 } | 303 } |
| 526 | 304 |
| 527 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { | 305 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { |
| 528 opaque_background_.SetBounds(GetLocalBounds()); | 306 opaque_background_.SetBounds(GetLocalBounds()); |
| 529 opaque_foreground_.SetBounds(GetLocalBounds()); | 307 opaque_foreground_.SetBounds(GetLocalBounds()); |
| 530 if (dimmer_) | 308 if (dimmer_view_) |
| 531 dimmer_->SetBounds(GetBoundsInScreen()); | 309 dimmer_view_->GetWidget()->SetBounds(GetBoundsInScreen()); |
| 532 } | |
| 533 | |
| 534 void ShelfWidget::DelegateView::OnWindowBoundsChanged( | |
| 535 aura::Window* window, | |
| 536 const gfx::Rect& old_bounds, | |
| 537 const gfx::Rect& new_bounds) { | |
| 538 // Coming here the shelf got repositioned and since the |dimmer_| is placed | |
| 539 // in screen coordinates and not relative to the parent it needs to be | |
| 540 // repositioned accordingly. | |
| 541 dimmer_->SetBounds(GetBoundsInScreen()); | |
| 542 } | 310 } |
| 543 | 311 |
| 544 void ShelfWidget::DelegateView::ForceUndimming(bool force) { | 312 void ShelfWidget::DelegateView::ForceUndimming(bool force) { |
| 545 if (GetDimmed()) | 313 if (GetDimmed()) |
| 546 dimmer_view_->ForceUndimming(force); | 314 dimmer_view_->ForceUndimming(force); |
| 547 } | 315 } |
| 548 | 316 |
| 549 int ShelfWidget::DelegateView::GetDimmingAlphaForTest() { | 317 int ShelfWidget::DelegateView::GetDimmingAlphaForTest() { |
| 550 if (GetDimmed()) | 318 if (GetDimmed()) |
| 551 return dimmer_view_->get_dimming_alpha_for_test(); | 319 return dimmer_view_->get_dimming_alpha_for_test(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 delegate_view_->set_focus_cycler(focus_cycler); | 523 delegate_view_->set_focus_cycler(focus_cycler); |
| 756 if (focus_cycler) | 524 if (focus_cycler) |
| 757 focus_cycler->AddWidget(this); | 525 focus_cycler->AddWidget(this); |
| 758 } | 526 } |
| 759 | 527 |
| 760 FocusCycler* ShelfWidget::GetFocusCycler() { | 528 FocusCycler* ShelfWidget::GetFocusCycler() { |
| 761 return delegate_view_->focus_cycler(); | 529 return delegate_view_->focus_cycler(); |
| 762 } | 530 } |
| 763 | 531 |
| 764 void ShelfWidget::Shutdown() { | 532 void ShelfWidget::Shutdown() { |
| 533 // Tear down the dimmer before |shelf_layout_manager_|, since the dimmer uses |
| 534 // |shelf_layout_manager_| to get the shelf's WmWindow, via WmShelfAura. |
| 535 delegate_view_->SetDimmed(false); |
| 536 |
| 765 // Shutting down the status area widget may cause some widgets (e.g. bubbles) | 537 // Shutting down the status area widget may cause some widgets (e.g. bubbles) |
| 766 // to close, so uninstall the ShelfLayoutManager event filters first. Don't | 538 // to close, so uninstall the ShelfLayoutManager event filters first. Don't |
| 767 // reset the pointer until later because other widgets (e.g. app list) may | 539 // reset the pointer until later because other widgets (e.g. app list) may |
| 768 // access it later in shutdown. | 540 // access it later in shutdown. |
| 769 if (shelf_layout_manager_) | 541 if (shelf_layout_manager_) |
| 770 shelf_layout_manager_->PrepareForShutdown(); | 542 shelf_layout_manager_->PrepareForShutdown(); |
| 771 | 543 |
| 772 if (status_area_widget_) { | 544 if (status_area_widget_) { |
| 773 background_animator_.RemoveObserver(status_area_widget_); | 545 background_animator_.RemoveObserver(status_area_widget_); |
| 774 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); | 546 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 return delegate_view_->disable_dimming_animations_for_test(); | 579 return delegate_view_->disable_dimming_animations_for_test(); |
| 808 } | 580 } |
| 809 | 581 |
| 810 void ShelfWidget::UpdateShelfItemBackground(int alpha) { | 582 void ShelfWidget::UpdateShelfItemBackground(int alpha) { |
| 811 if (shelf_) | 583 if (shelf_) |
| 812 shelf_->UpdateShelfItemBackground(alpha); | 584 shelf_->UpdateShelfItemBackground(alpha); |
| 813 } | 585 } |
| 814 | 586 |
| 815 void ShelfWidget::WillDeleteShelfLayoutManager() { | 587 void ShelfWidget::WillDeleteShelfLayoutManager() { |
| 816 shelf_layout_manager_->RemoveObserver(this); | 588 shelf_layout_manager_->RemoveObserver(this); |
| 817 shelf_layout_manager_ = NULL; | 589 shelf_layout_manager_ = nullptr; |
| 818 } | 590 } |
| 819 | 591 |
| 820 void ShelfWidget::OnMouseEvent(ui::MouseEvent* event) { | 592 void ShelfWidget::OnMouseEvent(ui::MouseEvent* event) { |
| 821 Widget::OnMouseEvent(event); | 593 Widget::OnMouseEvent(event); |
| 822 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | 594 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) |
| 823 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); | 595 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); |
| 824 } | 596 } |
| 825 | 597 |
| 826 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { | 598 void ShelfWidget::OnGestureEvent(ui::GestureEvent* event) { |
| 827 Widget::OnGestureEvent(event); | 599 Widget::OnGestureEvent(event); |
| 828 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | 600 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) |
| 829 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); | 601 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); |
| 830 } | 602 } |
| 831 | 603 |
| 832 } // namespace ash | 604 } // namespace ash |
| OLD | NEW |