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