summaryrefslogtreecommitdiff
path: root/chromium/ui/views/win/appbar.cc
blob: 062eb34c038ef22151d01dd68b7fc7b983cc1a73 (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
76
77
78
79
80
// Copyright 2013 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 "ui/views/win/appbar.h"

#include <shellapi.h>

#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/location.h"
#include "base/threading/worker_pool.h"
#include "base/win/scoped_com_initializer.h"
#include "ui/views/widget/monitor_win.h"

namespace views {

namespace {

void GetEdgesOnWorkerThread(HMONITOR monitor, int* edge) {
  base::win::ScopedCOMInitializer com_initializer;
  *edge = 0;
  if (GetTopmostAutoHideTaskbarForEdge(ABE_LEFT, monitor))
    *edge = Appbar::EDGE_LEFT;
  if (GetTopmostAutoHideTaskbarForEdge(ABE_TOP, monitor))
    *edge = Appbar::EDGE_TOP;
  if (GetTopmostAutoHideTaskbarForEdge(ABE_RIGHT, monitor))
    *edge = Appbar::EDGE_RIGHT;
  if (GetTopmostAutoHideTaskbarForEdge(ABE_BOTTOM, monitor))
    *edge = Appbar::EDGE_BOTTOM;
}

}

// static
Appbar* Appbar::instance() {
  static Appbar* appbar = NULL;
  if (!appbar)
    appbar = new Appbar();
  return appbar;
}

int Appbar::GetAutohideEdges(HMONITOR monitor, const base::Closure& callback) {
  if (!in_callback_) {
    int* edge = new int;
    base::WorkerPool::PostTaskAndReply(
        FROM_HERE,
        base::Bind(&GetEdgesOnWorkerThread,
                   monitor,
                   base::Unretained(edge)),
        base::Bind(&Appbar::OnGotEdges,
                   weak_factory_.GetWeakPtr(),
                   callback,
                   monitor,
                   edge_map_[monitor],
                   base::Owned(edge)),
        false);
  }
  return edge_map_[monitor];
}

Appbar::Appbar() : weak_factory_(this), in_callback_(false) {
}

Appbar::~Appbar() {
}

void Appbar::OnGotEdges(const base::Closure& callback,
                        HMONITOR monitor,
                        int returned_edges,
                        int* edges) {
  edge_map_[monitor] = *edges;
  if (returned_edges == *edges)
    return;

  base::AutoReset<bool> in_callback_setter(&in_callback_, true);
  callback.Run();
}

}  // namespace views