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