summaryrefslogtreecommitdiffstats
path: root/ash/wm/panels/attached_panel_window_targeter.cc
blob: 4e8b8f71383f2116db099741406a41e7bcc87ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/wm/panels/attached_panel_window_targeter.h"

#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/wm/panels/panel_layout_manager.h"

namespace ash {

AttachedPanelWindowTargeter::AttachedPanelWindowTargeter(
    aura::Window* container,
    const gfx::Insets& default_mouse_extend,
    const gfx::Insets& default_touch_extend,
    PanelLayoutManager* panel_layout_manager)
    : ::wm::EasyResizeWindowTargeter(container,
                                     default_mouse_extend,
                                     default_touch_extend),
      panel_container_(container),
      panel_layout_manager_(panel_layout_manager),
      default_touch_extend_(default_touch_extend) {
  Shell::GetInstance()->AddShellObserver(this);
}

AttachedPanelWindowTargeter::~AttachedPanelWindowTargeter() {
  Shell::GetInstance()->RemoveShellObserver(this);
}

void AttachedPanelWindowTargeter::OnShelfCreatedForRootWindow(
    aura::Window* root_window) {
  UpdateTouchExtend(root_window);
}

void AttachedPanelWindowTargeter::OnShelfAlignmentChanged(
    aura::Window* root_window) {
  // Don't update the touch insets if the shelf has not yet been created.
  if (!panel_layout_manager_->shelf())
    return;

  UpdateTouchExtend(root_window);
}

void AttachedPanelWindowTargeter::UpdateTouchExtend(aura::Window* root_window) {
  // Only update the touch insets for panels if they are attached to the shelf
  // in |root_window|.
  if (panel_container_->GetRootWindow() != root_window)
    return;

  DCHECK(panel_layout_manager_->shelf());

  gfx::Insets touch(default_touch_extend_);
  switch (panel_layout_manager_->shelf()->alignment()) {
    case SHELF_ALIGNMENT_BOTTOM:
      touch = gfx::Insets(touch.top(), touch.left(), 0, touch.right());
      break;
    case SHELF_ALIGNMENT_LEFT:
      touch = gfx::Insets(touch.top(), 0, touch.bottom(), touch.right());
      break;
    case SHELF_ALIGNMENT_RIGHT:
      touch = gfx::Insets(touch.top(), touch.left(), touch.bottom(), 0);
      break;
    case SHELF_ALIGNMENT_TOP:
      touch = gfx::Insets(0, touch.left(), touch.bottom(), touch.right());
      break;
    default:
      NOTREACHED();
      return;
  }

  set_touch_extend(touch);
}

}  // namespace ash