OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/panels/attached_panel_window_targeter.h" | 5 #include "ash/wm/panels/attached_panel_window_targeter.h" |
6 | 6 |
7 #include "ash/shelf/shelf.h" | 7 #include "ash/shelf/shelf.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/panels/panel_layout_manager.h" | 9 #include "ash/wm/panels/panel_layout_manager.h" |
10 #include "ash/wm_window.h" | |
11 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
12 | 11 |
13 namespace ash { | 12 namespace ash { |
14 | 13 |
15 AttachedPanelWindowTargeter::AttachedPanelWindowTargeter( | 14 AttachedPanelWindowTargeter::AttachedPanelWindowTargeter( |
16 aura::Window* container, | 15 aura::Window* container, |
17 const gfx::Insets& default_mouse_extend, | 16 const gfx::Insets& default_mouse_extend, |
18 const gfx::Insets& default_touch_extend, | 17 const gfx::Insets& default_touch_extend, |
19 PanelLayoutManager* panel_layout_manager) | 18 PanelLayoutManager* panel_layout_manager) |
20 : ::wm::EasyResizeWindowTargeter(container, | 19 : ::wm::EasyResizeWindowTargeter(container, |
21 default_mouse_extend, | 20 default_mouse_extend, |
22 default_touch_extend), | 21 default_touch_extend), |
23 panel_container_(container), | 22 panel_container_(container), |
24 panel_layout_manager_(panel_layout_manager), | 23 panel_layout_manager_(panel_layout_manager), |
25 default_touch_extend_(default_touch_extend) { | 24 default_touch_extend_(default_touch_extend) { |
26 Shell::Get()->AddShellObserver(this); | 25 Shell::Get()->AddShellObserver(this); |
27 } | 26 } |
28 | 27 |
29 AttachedPanelWindowTargeter::~AttachedPanelWindowTargeter() { | 28 AttachedPanelWindowTargeter::~AttachedPanelWindowTargeter() { |
30 Shell::Get()->RemoveShellObserver(this); | 29 Shell::Get()->RemoveShellObserver(this); |
31 } | 30 } |
32 | 31 |
33 void AttachedPanelWindowTargeter::OnShelfCreatedForRootWindow( | 32 void AttachedPanelWindowTargeter::OnShelfCreatedForRootWindow( |
34 WmWindow* root_window) { | 33 aura::Window* root_window) { |
35 UpdateTouchExtend(WmWindow::GetAuraWindow(root_window)); | 34 UpdateTouchExtend(root_window); |
36 } | 35 } |
37 | 36 |
38 void AttachedPanelWindowTargeter::OnShelfAlignmentChanged( | 37 void AttachedPanelWindowTargeter::OnShelfAlignmentChanged( |
39 WmWindow* root_window) { | 38 aura::Window* root_window) { |
40 // Don't update the touch insets if the shelf has not yet been created. | 39 // Don't update the touch insets if the shelf has not yet been created. |
41 if (!panel_layout_manager_->shelf()) | 40 if (!panel_layout_manager_->shelf()) |
42 return; | 41 return; |
43 | 42 |
44 UpdateTouchExtend(WmWindow::GetAuraWindow(root_window)); | 43 UpdateTouchExtend(root_window); |
45 } | 44 } |
46 | 45 |
47 void AttachedPanelWindowTargeter::UpdateTouchExtend(aura::Window* root_window) { | 46 void AttachedPanelWindowTargeter::UpdateTouchExtend(aura::Window* root_window) { |
48 // Only update the touch insets for panels if they are attached to the shelf | 47 // Only update the touch insets for panels if they are attached to the shelf |
49 // in |root_window|. | 48 // in |root_window|. |
50 if (panel_container_->GetRootWindow() != root_window) | 49 if (panel_container_->GetRootWindow() != root_window) |
51 return; | 50 return; |
52 | 51 |
53 DCHECK(panel_layout_manager_->shelf()); | 52 DCHECK(panel_layout_manager_->shelf()); |
54 gfx::Insets touch(default_touch_extend_); | 53 gfx::Insets touch(default_touch_extend_); |
55 switch (panel_layout_manager_->shelf()->alignment()) { | 54 switch (panel_layout_manager_->shelf()->alignment()) { |
56 case SHELF_ALIGNMENT_BOTTOM: | 55 case SHELF_ALIGNMENT_BOTTOM: |
57 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 56 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
58 set_touch_extend( | 57 set_touch_extend( |
59 gfx::Insets(touch.top(), touch.left(), 0, touch.right())); | 58 gfx::Insets(touch.top(), touch.left(), 0, touch.right())); |
60 break; | 59 break; |
61 case SHELF_ALIGNMENT_LEFT: | 60 case SHELF_ALIGNMENT_LEFT: |
62 set_touch_extend( | 61 set_touch_extend( |
63 gfx::Insets(touch.top(), 0, touch.bottom(), touch.right())); | 62 gfx::Insets(touch.top(), 0, touch.bottom(), touch.right())); |
64 break; | 63 break; |
65 case SHELF_ALIGNMENT_RIGHT: | 64 case SHELF_ALIGNMENT_RIGHT: |
66 set_touch_extend( | 65 set_touch_extend( |
67 gfx::Insets(touch.top(), touch.left(), touch.bottom(), 0)); | 66 gfx::Insets(touch.top(), touch.left(), touch.bottom(), 0)); |
68 break; | 67 break; |
69 } | 68 } |
70 } | 69 } |
71 | 70 |
72 } // namespace ash | 71 } // namespace ash |
OLD | NEW |