18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// Copyright 2014 The Chromium Authors. All rights reserved. 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// Use of this source code is governed by a BSD-style license that can be 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// found in the LICENSE file. 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "ash/wm/panels/attached_panel_window_targeter.h" 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "ash/shelf/shelf.h" 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "ash/shell.h" 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "ash/wm/panels/panel_layout_manager.h" 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comnamespace ash { 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comAttachedPanelWindowTargeter::AttachedPanelWindowTargeter( 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aura::Window* container, 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const gfx::Insets& default_mouse_extend, 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const gfx::Insets& default_touch_extend, 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PanelLayoutManager* panel_layout_manager) 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : ::wm::EasyResizeWindowTargeter(container, 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default_mouse_extend, 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default_touch_extend), 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com panel_container_(container), 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com panel_layout_manager_(panel_layout_manager), 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default_touch_extend_(default_touch_extend) { 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Shell::GetInstance()->AddShellObserver(this); 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 277ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgAttachedPanelWindowTargeter::~AttachedPanelWindowTargeter() { 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Shell::GetInstance()->RemoveShellObserver(this); 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid AttachedPanelWindowTargeter::OnShelfCreatedForRootWindow( 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aura::Window* root_window) { 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com UpdateTouchExtend(root_window); 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid AttachedPanelWindowTargeter::OnShelfAlignmentChanged( 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com aura::Window* root_window) { 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Don't update the touch insets if the shelf has not yet been created. 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!panel_layout_manager_->shelf()) 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com UpdateTouchExtend(root_window); 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid AttachedPanelWindowTargeter::UpdateTouchExtend(aura::Window* root_window) { 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Only update the touch insets for panels if they are attached to the shelf 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // in |root_window|. 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (panel_container_->GetRootWindow() != root_window) 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return; 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com DCHECK(panel_layout_manager_->shelf()); 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com gfx::Insets touch(default_touch_extend_); 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (panel_layout_manager_->shelf()->alignment()) { 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SHELF_ALIGNMENT_BOTTOM: 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com touch = gfx::Insets(touch.top(), touch.left(), 0, touch.right()); 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case SHELF_ALIGNMENT_LEFT: 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com touch = gfx::Insets(touch.top(), 0, touch.bottom(), touch.right()); 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 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