| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_window_targeter.h" | 5 #include "ash/shelf/shelf_window_targeter.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_constants.h" | 7 #include "ash/common/shelf/shelf_constants.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/wm_window.h" | 9 #include "ash/common/wm_window.h" |
| 10 #include "ash/public/cpp/shelf_types.h" | 10 #include "ash/public/cpp/shelf_types.h" |
| 11 #include "ui/aura/window.h" |
| 11 | 12 |
| 12 namespace ash { | 13 namespace ash { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 gfx::Insets GetInsetsForAlignment(int distance, ShelfAlignment alignment) { | 17 gfx::Insets GetInsetsForAlignment(int distance, ShelfAlignment alignment) { |
| 17 if (alignment == SHELF_ALIGNMENT_LEFT) | 18 if (alignment == SHELF_ALIGNMENT_LEFT) |
| 18 return gfx::Insets(0, 0, 0, distance); | 19 return gfx::Insets(0, 0, 0, distance); |
| 19 if (alignment == SHELF_ALIGNMENT_RIGHT) | 20 if (alignment == SHELF_ALIGNMENT_RIGHT) |
| 20 return gfx::Insets(0, distance, 0, 0); | 21 return gfx::Insets(0, distance, 0, 0); |
| 21 return gfx::Insets(distance, 0, 0, 0); | 22 return gfx::Insets(distance, 0, 0, 0); |
| 22 } | 23 } |
| 23 | 24 |
| 24 } // namespace | 25 } // namespace |
| 25 | 26 |
| 26 ShelfWindowTargeter::ShelfWindowTargeter(WmWindow* container, WmShelf* shelf) | 27 ShelfWindowTargeter::ShelfWindowTargeter(WmWindow* container, WmShelf* shelf) |
| 27 : ::wm::EasyResizeWindowTargeter(WmWindow::GetAuraWindow(container), | 28 : ::wm::EasyResizeWindowTargeter(WmWindow::GetAuraWindow(container), |
| 28 gfx::Insets(), | 29 gfx::Insets(), |
| 29 gfx::Insets()), | 30 gfx::Insets()), |
| 30 shelf_(shelf) { | 31 shelf_(shelf) { |
| 31 WillChangeVisibilityState(shelf_->GetVisibilityState()); | 32 WillChangeVisibilityState(shelf_->GetVisibilityState()); |
| 32 container->AddObserver(this); | 33 container->aura_window()->AddObserver(this); |
| 33 shelf_->AddObserver(this); | 34 shelf_->AddObserver(this); |
| 34 } | 35 } |
| 35 | 36 |
| 36 ShelfWindowTargeter::~ShelfWindowTargeter() { | 37 ShelfWindowTargeter::~ShelfWindowTargeter() { |
| 37 // Ensure that the observers were removed and the shelf pointer was cleared. | 38 // Ensure that the observers were removed and the shelf pointer was cleared. |
| 38 DCHECK(!shelf_); | 39 DCHECK(!shelf_); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void ShelfWindowTargeter::OnWindowDestroying(WmWindow* window) { | 42 void ShelfWindowTargeter::OnWindowDestroying(aura::Window* window) { |
| 42 window->RemoveObserver(this); | 43 window->RemoveObserver(this); |
| 43 shelf_->RemoveObserver(this); | 44 shelf_->RemoveObserver(this); |
| 44 shelf_ = nullptr; | 45 shelf_ = nullptr; |
| 45 } | 46 } |
| 46 | 47 |
| 47 void ShelfWindowTargeter::WillChangeVisibilityState( | 48 void ShelfWindowTargeter::WillChangeVisibilityState( |
| 48 ShelfVisibilityState new_state) { | 49 ShelfVisibilityState new_state) { |
| 49 gfx::Insets mouse_insets; | 50 gfx::Insets mouse_insets; |
| 50 gfx::Insets touch_insets; | 51 gfx::Insets touch_insets; |
| 51 if (new_state == SHELF_VISIBLE) { | 52 if (new_state == SHELF_VISIBLE) { |
| 52 // Let clicks at the very top of the shelf through so windows can be | 53 // Let clicks at the very top of the shelf through so windows can be |
| 53 // resized with the bottom-right corner and bottom edge. | 54 // resized with the bottom-right corner and bottom edge. |
| 54 mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset, | 55 mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset, |
| 55 shelf_->GetAlignment()); | 56 shelf_->GetAlignment()); |
| 56 } else if (new_state == SHELF_AUTO_HIDE) { | 57 } else if (new_state == SHELF_AUTO_HIDE) { |
| 57 // Extend the touch hit target out a bit to allow users to drag shelf out | 58 // Extend the touch hit target out a bit to allow users to drag shelf out |
| 58 // while hidden. | 59 // while hidden. |
| 59 touch_insets = GetInsetsForAlignment(-kWorkspaceAreaAutoHideInset, | 60 touch_insets = GetInsetsForAlignment(-kWorkspaceAreaAutoHideInset, |
| 60 shelf_->GetAlignment()); | 61 shelf_->GetAlignment()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 set_mouse_extend(mouse_insets); | 64 set_mouse_extend(mouse_insets); |
| 64 set_touch_extend(touch_insets); | 65 set_touch_extend(touch_insets); |
| 65 } | 66 } |
| 66 | 67 |
| 67 } // namespace ash | 68 } // namespace ash |
| OLD | NEW |