OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/focus_cycler.h" | 8 #include "ash/focus_cycler.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/session/session_state_delegate.h" | 10 #include "ash/session/session_state_delegate.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 // Class used to slightly dim shelf items when maximized and visible. | 52 // Class used to slightly dim shelf items when maximized and visible. |
53 class DimmerView : public views::View, | 53 class DimmerView : public views::View, |
54 public views::WidgetDelegate, | 54 public views::WidgetDelegate, |
55 ash::BackgroundAnimatorDelegate { | 55 ash::BackgroundAnimatorDelegate { |
56 public: | 56 public: |
57 // If |disable_dimming_animations_for_test| is set, all alpha animations will | 57 // If |disable_dimming_animations_for_test| is set, all alpha animations will |
58 // be performed instantly. | 58 // be performed instantly. |
59 DimmerView(ash::ShelfWidget* shelf_widget, | 59 DimmerView(ash::ShelfWidget* shelf_widget, |
60 bool disable_dimming_animations_for_test); | 60 bool disable_dimming_animations_for_test); |
61 virtual ~DimmerView(); | 61 ~DimmerView() override; |
62 | 62 |
63 // Called by |DimmerEventFilter| when the mouse |hovered| state changes. | 63 // Called by |DimmerEventFilter| when the mouse |hovered| state changes. |
64 void SetHovered(bool hovered); | 64 void SetHovered(bool hovered); |
65 | 65 |
66 // Force the dimmer to be undimmed. | 66 // Force the dimmer to be undimmed. |
67 void ForceUndimming(bool force); | 67 void ForceUndimming(bool force); |
68 | 68 |
69 // views::WidgetDelegate overrides: | 69 // views::WidgetDelegate overrides: |
70 virtual views::Widget* GetWidget() override { | 70 views::Widget* GetWidget() override { return View::GetWidget(); } |
71 return View::GetWidget(); | 71 const views::Widget* GetWidget() const override { return View::GetWidget(); } |
72 } | |
73 virtual const views::Widget* GetWidget() const override { | |
74 return View::GetWidget(); | |
75 } | |
76 | 72 |
77 // ash::BackgroundAnimatorDelegate overrides: | 73 // ash::BackgroundAnimatorDelegate overrides: |
78 virtual void UpdateBackground(int alpha) override { | 74 void UpdateBackground(int alpha) override { |
79 alpha_ = alpha; | 75 alpha_ = alpha; |
80 SchedulePaint(); | 76 SchedulePaint(); |
81 } | 77 } |
82 | 78 |
83 // views::View overrides: | 79 // views::View overrides: |
84 virtual void OnPaintBackground(gfx::Canvas* canvas) override; | 80 void OnPaintBackground(gfx::Canvas* canvas) override; |
85 | 81 |
86 // A function to test the current alpha used. | 82 // A function to test the current alpha used. |
87 int get_dimming_alpha_for_test() { return alpha_; } | 83 int get_dimming_alpha_for_test() { return alpha_; } |
88 | 84 |
89 private: | 85 private: |
90 // This class monitors mouse events to see if it is on top of the shelf. | 86 // This class monitors mouse events to see if it is on top of the shelf. |
91 class DimmerEventFilter : public ui::EventHandler { | 87 class DimmerEventFilter : public ui::EventHandler { |
92 public: | 88 public: |
93 explicit DimmerEventFilter(DimmerView* owner); | 89 explicit DimmerEventFilter(DimmerView* owner); |
94 virtual ~DimmerEventFilter(); | 90 ~DimmerEventFilter() override; |
95 | 91 |
96 // Overridden from ui::EventHandler: | 92 // Overridden from ui::EventHandler: |
97 virtual void OnMouseEvent(ui::MouseEvent* event) override; | 93 void OnMouseEvent(ui::MouseEvent* event) override; |
98 virtual void OnTouchEvent(ui::TouchEvent* event) override; | 94 void OnTouchEvent(ui::TouchEvent* event) override; |
99 | 95 |
100 private: | 96 private: |
101 // The owning class. | 97 // The owning class. |
102 DimmerView* owner_; | 98 DimmerView* owner_; |
103 | 99 |
104 // TRUE if the mouse is inside the shelf. | 100 // TRUE if the mouse is inside the shelf. |
105 bool mouse_inside_; | 101 bool mouse_inside_; |
106 | 102 |
107 // TRUE if a touch event is inside the shelf. | 103 // TRUE if a touch event is inside the shelf. |
108 bool touch_inside_; | 104 bool touch_inside_; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 public ash::ShelfLayoutManagerObserver { | 239 public ash::ShelfLayoutManagerObserver { |
244 public: | 240 public: |
245 ShelfWindowTargeter(aura::Window* container, | 241 ShelfWindowTargeter(aura::Window* container, |
246 ShelfLayoutManager* shelf) | 242 ShelfLayoutManager* shelf) |
247 : wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()), | 243 : wm::EasyResizeWindowTargeter(container, gfx::Insets(), gfx::Insets()), |
248 shelf_(shelf) { | 244 shelf_(shelf) { |
249 WillChangeVisibilityState(shelf_->visibility_state()); | 245 WillChangeVisibilityState(shelf_->visibility_state()); |
250 shelf_->AddObserver(this); | 246 shelf_->AddObserver(this); |
251 } | 247 } |
252 | 248 |
253 virtual ~ShelfWindowTargeter() { | 249 ~ShelfWindowTargeter() override { |
254 // |shelf_| may have been destroyed by this time. | 250 // |shelf_| may have been destroyed by this time. |
255 if (shelf_) | 251 if (shelf_) |
256 shelf_->RemoveObserver(this); | 252 shelf_->RemoveObserver(this); |
257 } | 253 } |
258 | 254 |
259 private: | 255 private: |
260 gfx::Insets GetInsetsForAlignment(int distance, | 256 gfx::Insets GetInsetsForAlignment(int distance, |
261 ash::ShelfAlignment alignment) { | 257 ash::ShelfAlignment alignment) { |
262 switch (alignment) { | 258 switch (alignment) { |
263 case ash::SHELF_ALIGNMENT_BOTTOM: | 259 case ash::SHELF_ALIGNMENT_BOTTOM: |
264 return gfx::Insets(distance, 0, 0, 0); | 260 return gfx::Insets(distance, 0, 0, 0); |
265 case ash::SHELF_ALIGNMENT_LEFT: | 261 case ash::SHELF_ALIGNMENT_LEFT: |
266 return gfx::Insets(0, 0, 0, distance); | 262 return gfx::Insets(0, 0, 0, distance); |
267 case ash::SHELF_ALIGNMENT_RIGHT: | 263 case ash::SHELF_ALIGNMENT_RIGHT: |
268 return gfx::Insets(0, distance, 0, 0); | 264 return gfx::Insets(0, distance, 0, 0); |
269 case ash::SHELF_ALIGNMENT_TOP: | 265 case ash::SHELF_ALIGNMENT_TOP: |
270 return gfx::Insets(0, 0, distance, 0); | 266 return gfx::Insets(0, 0, distance, 0); |
271 } | 267 } |
272 NOTREACHED(); | 268 NOTREACHED(); |
273 return gfx::Insets(); | 269 return gfx::Insets(); |
274 } | 270 } |
275 | 271 |
276 // ash::ShelfLayoutManagerObserver: | 272 // ash::ShelfLayoutManagerObserver: |
277 virtual void WillDeleteShelf() override { | 273 void WillDeleteShelf() override { shelf_ = NULL; } |
278 shelf_ = NULL; | |
279 } | |
280 | 274 |
281 virtual void WillChangeVisibilityState( | 275 void WillChangeVisibilityState(ash::ShelfVisibilityState new_state) override { |
282 ash::ShelfVisibilityState new_state) override { | |
283 gfx::Insets mouse_insets; | 276 gfx::Insets mouse_insets; |
284 gfx::Insets touch_insets; | 277 gfx::Insets touch_insets; |
285 if (new_state == ash::SHELF_VISIBLE) { | 278 if (new_state == ash::SHELF_VISIBLE) { |
286 // Let clicks at the very top of the shelf through so windows can be | 279 // Let clicks at the very top of the shelf through so windows can be |
287 // resized with the bottom-right corner and bottom edge. | 280 // resized with the bottom-right corner and bottom edge. |
288 mouse_insets = GetInsetsForAlignment( | 281 mouse_insets = GetInsetsForAlignment( |
289 ShelfLayoutManager::kWorkspaceAreaVisibleInset, | 282 ShelfLayoutManager::kWorkspaceAreaVisibleInset, |
290 shelf_->GetAlignment()); | 283 shelf_->GetAlignment()); |
291 } else if (new_state == ash::SHELF_AUTO_HIDE) { | 284 } else if (new_state == ash::SHELF_AUTO_HIDE) { |
292 // Extend the touch hit target out a bit to allow users to drag shelf out | 285 // Extend the touch hit target out a bit to allow users to drag shelf out |
(...skipping 17 matching lines...) Expand all Loading... |
310 namespace ash { | 303 namespace ash { |
311 | 304 |
312 // The contents view of the Shelf. This view contains ShelfView and | 305 // The contents view of the Shelf. This view contains ShelfView and |
313 // sizes it to the width of the shelf minus the size of the status area. | 306 // sizes it to the width of the shelf minus the size of the status area. |
314 class ShelfWidget::DelegateView : public views::WidgetDelegate, | 307 class ShelfWidget::DelegateView : public views::WidgetDelegate, |
315 public views::AccessiblePaneView, | 308 public views::AccessiblePaneView, |
316 public BackgroundAnimatorDelegate, | 309 public BackgroundAnimatorDelegate, |
317 public aura::WindowObserver { | 310 public aura::WindowObserver { |
318 public: | 311 public: |
319 explicit DelegateView(ShelfWidget* shelf); | 312 explicit DelegateView(ShelfWidget* shelf); |
320 virtual ~DelegateView(); | 313 ~DelegateView() override; |
321 | 314 |
322 void set_focus_cycler(FocusCycler* focus_cycler) { | 315 void set_focus_cycler(FocusCycler* focus_cycler) { |
323 focus_cycler_ = focus_cycler; | 316 focus_cycler_ = focus_cycler; |
324 } | 317 } |
325 FocusCycler* focus_cycler() { return focus_cycler_; } | 318 FocusCycler* focus_cycler() { return focus_cycler_; } |
326 | 319 |
327 ui::Layer* opaque_background() { return &opaque_background_; } | 320 ui::Layer* opaque_background() { return &opaque_background_; } |
328 ui::Layer* opaque_foreground() { return &opaque_foreground_; } | 321 ui::Layer* opaque_foreground() { return &opaque_foreground_; } |
329 | 322 |
330 // Set if the shelf area is dimmed (eg when a window is maximized). | 323 // Set if the shelf area is dimmed (eg when a window is maximized). |
331 void SetDimmed(bool dimmed); | 324 void SetDimmed(bool dimmed); |
332 bool GetDimmed() const; | 325 bool GetDimmed() const; |
333 | 326 |
334 void SetParentLayer(ui::Layer* layer); | 327 void SetParentLayer(ui::Layer* layer); |
335 | 328 |
336 // views::View overrides: | 329 // views::View overrides: |
337 virtual void OnPaintBackground(gfx::Canvas* canvas) override; | 330 void OnPaintBackground(gfx::Canvas* canvas) override; |
338 | 331 |
339 // views::WidgetDelegateView overrides: | 332 // views::WidgetDelegateView overrides: |
340 virtual views::Widget* GetWidget() override { | 333 views::Widget* GetWidget() override { return View::GetWidget(); } |
341 return View::GetWidget(); | 334 const views::Widget* GetWidget() const override { return View::GetWidget(); } |
342 } | |
343 virtual const views::Widget* GetWidget() const override { | |
344 return View::GetWidget(); | |
345 } | |
346 | 335 |
347 virtual bool CanActivate() const override; | 336 bool CanActivate() const override; |
348 virtual void Layout() override; | 337 void Layout() override; |
349 virtual void ReorderChildLayers(ui::Layer* parent_layer) override; | 338 void ReorderChildLayers(ui::Layer* parent_layer) override; |
350 // This will be called when the parent local bounds change. | 339 // This will be called when the parent local bounds change. |
351 virtual void OnBoundsChanged(const gfx::Rect& old_bounds) override; | 340 void OnBoundsChanged(const gfx::Rect& old_bounds) override; |
352 | 341 |
353 // aura::WindowObserver overrides: | 342 // aura::WindowObserver overrides: |
354 // This will be called when the shelf itself changes its absolute position. | 343 // This will be called when the shelf itself changes its absolute position. |
355 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs | 344 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs |
356 // to be repositioned. The difference to the OnBoundsChanged call above is | 345 // to be repositioned. The difference to the OnBoundsChanged call above is |
357 // that this gets also triggered when the shelf only moves. | 346 // that this gets also triggered when the shelf only moves. |
358 virtual void OnWindowBoundsChanged(aura::Window* window, | 347 void OnWindowBoundsChanged(aura::Window* window, |
359 const gfx::Rect& old_bounds, | 348 const gfx::Rect& old_bounds, |
360 const gfx::Rect& new_bounds) override; | 349 const gfx::Rect& new_bounds) override; |
361 | 350 |
362 // BackgroundAnimatorDelegate overrides: | 351 // BackgroundAnimatorDelegate overrides: |
363 virtual void UpdateBackground(int alpha) override; | 352 void UpdateBackground(int alpha) override; |
364 | 353 |
365 // Force the shelf to be presented in an undimmed state. | 354 // Force the shelf to be presented in an undimmed state. |
366 void ForceUndimming(bool force); | 355 void ForceUndimming(bool force); |
367 | 356 |
368 // A function to test the current alpha used by the dimming bar. If there is | 357 // A function to test the current alpha used by the dimming bar. If there is |
369 // no dimmer active, the function will return -1. | 358 // no dimmer active, the function will return -1. |
370 int GetDimmingAlphaForTest(); | 359 int GetDimmingAlphaForTest(); |
371 | 360 |
372 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if | 361 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if |
373 // the dimmer is inactive. | 362 // the dimmer is inactive. |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 DCHECK(delegate_view_); | 828 DCHECK(delegate_view_); |
840 return delegate_view_->disable_dimming_animations_for_test(); | 829 return delegate_view_->disable_dimming_animations_for_test(); |
841 } | 830 } |
842 | 831 |
843 void ShelfWidget::WillDeleteShelf() { | 832 void ShelfWidget::WillDeleteShelf() { |
844 shelf_layout_manager_->RemoveObserver(this); | 833 shelf_layout_manager_->RemoveObserver(this); |
845 shelf_layout_manager_ = NULL; | 834 shelf_layout_manager_ = NULL; |
846 } | 835 } |
847 | 836 |
848 } // namespace ash | 837 } // namespace ash |
OLD | NEW |