summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/balloon_collection_win.cc
blob: 45f7921b139bccfcf511089d494d99dc2c1ff52a (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
// Copyright (c) 2009 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/notifications/balloon_collection.h"

#include "base/gfx/rect.h"
#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/views/notifications/balloon_view.h"

namespace {

void GetMainScreenWorkArea(gfx::Rect* bounds) {
  DCHECK(bounds);
  RECT work_area = {0};
  if (::SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0)) {
    bounds->SetRect(work_area.left, work_area.top,
                    work_area.right, work_area.bottom);
  } else {
    // If call to ::SystemParametersInfo fails for some reason, we simply get
    // the full screen size as an alternative.
    bounds->SetRect(0, 0,
                    ::GetSystemMetrics(SM_CXSCREEN) - 1,
                    ::GetSystemMetrics(SM_CYSCREEN) - 1);
  }
}

}  // namespace

Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
                                            Profile* profile) {
  Balloon* balloon = new Balloon(notification, profile, this);
  balloon->set_view(new BalloonViewImpl());
  gfx::Size size(layout_.min_balloon_width(), layout_.min_balloon_height());
  balloon->set_size(size);
  return balloon;
}

bool BalloonCollectionImpl::Layout::RefreshSystemMetrics() {
  bool changed = false;

  gfx::Rect new_work_area(work_area_.x(), work_area_.y(),
                          work_area_.width(), work_area_.height());
  GetMainScreenWorkArea(&new_work_area);
  if (!work_area_.Equals(new_work_area)) {
    work_area_.SetRect(new_work_area.x(), new_work_area.y(),
                       new_work_area.width(), new_work_area.height());
    changed = true;
  }

  return changed;
}