Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / wm / panels / attached_panel_window_targeter.cc
blob4e8b8f71383f2116db099741406a41e7bcc87ebf
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"
8 #include "ash/shell.h"
9 #include "ash/wm/panels/panel_layout_manager.h"
11 namespace ash {
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,
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);
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())
40 return;
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
47 // in |root_window|.
48 if (panel_container_->GetRootWindow() != root_window)
49 return;
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());
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;
72 set_touch_extend(touch);
75 } // namespace ash