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.
5 #include "ash/wm/panels/attached_panel_window_targeter.h"
7 #include "ash/shelf/shelf.h"
9 #include "ash/wm/panels/panel_layout_manager.h"
13 AttachedPanelWindowTargeter::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
,
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);
27 AttachedPanelWindowTargeter::~AttachedPanelWindowTargeter() {
28 Shell::GetInstance()->RemoveShellObserver(this);
31 void AttachedPanelWindowTargeter::OnShelfCreatedForRootWindow(
32 aura::Window
* root_window
) {
33 UpdateTouchExtend(root_window
);
36 void 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())
42 UpdateTouchExtend(root_window
);
45 void AttachedPanelWindowTargeter::UpdateTouchExtend(aura::Window
* root_window
) {
46 // Only update the touch insets for panels if they are attached to the shelf
48 if (panel_container_
->GetRootWindow() != root_window
)
51 DCHECK(panel_layout_manager_
->shelf());
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());
58 case SHELF_ALIGNMENT_LEFT
:
59 touch
= gfx::Insets(touch
.top(), 0, touch
.bottom(), touch
.right());
61 case SHELF_ALIGNMENT_RIGHT
:
62 touch
= gfx::Insets(touch
.top(), touch
.left(), touch
.bottom(), 0);
64 case SHELF_ALIGNMENT_TOP
:
65 touch
= gfx::Insets(0, touch
.left(), touch
.bottom(), touch
.right());
72 set_touch_extend(touch
);