summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/panels/panel_mouse_watcher.cc
blob: 77e5f5bdb829bbb0b13488e4186b4ea5c617b178 (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
// Copyright (c) 2011 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 "chrome/browser/ui/panels/panel_mouse_watcher.h"

#include "chrome/browser/ui/panels/panel_manager.h"

PanelMouseWatcher::PanelMouseWatcher()
    : bring_up_titlebar_(false), is_testing_mode_enabled_(false) {
}

PanelMouseWatcher::~PanelMouseWatcher() {
  DCHECK(subscribers_.size() == 0);
}

void PanelMouseWatcher::AddSubscriber(NativePanel* native_panel) {
  if (is_testing_mode_enabled_)
    return;

  if (subscribers_.count(native_panel) == 0) {
    subscribers_.insert(native_panel);
    DCHECK_LE(subscribers_.size(),
              static_cast<size_t>(PanelManager::GetInstance()->num_panels()));

    if (subscribers_.size() == 1)
      Start();
  }
}

void PanelMouseWatcher::RemoveSubscriber(NativePanel* native_panel) {
  if (is_testing_mode_enabled_)
    return;

  DCHECK(subscribers_.count(native_panel) == 1);
  subscribers_.erase(native_panel);

  if (subscribers_.size() == 0)
    Stop();
}

bool PanelMouseWatcher::IsSubscribed(NativePanel* native_panel) const {
  return subscribers_.count(native_panel) != 0;
}

void PanelMouseWatcher::EnableTestingMode() {
  is_testing_mode_enabled_ = true;
  DCHECK(subscribers_.size() == 0);
}

void PanelMouseWatcher::HandleMouseMovement(
    const gfx::Point& mouse_position) {
  PanelManager* panel_manager = PanelManager::GetInstance();

  bool bring_up_titlebar =
      panel_manager->ShouldBringUpTitlebars(
          mouse_position.x(), mouse_position.y());
  if (bring_up_titlebar == bring_up_titlebar_)
    return;
  bring_up_titlebar_ = bring_up_titlebar;
  panel_manager->BringUpOrDownTitlebars(bring_up_titlebar);
}