File: desktop_popup_alignment_delegate.cc

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (104 lines) | stat: -rw-r--r-- 3,395 bytes parent folder | download | duplicates (2)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 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 "ui/message_center/views/desktop_popup_alignment_delegate.h"

#include "ui/gfx/display.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/screen.h"
#include "ui/message_center/message_center_style.h"
#include "ui/message_center/views/message_popup_collection.h"

namespace message_center {

DesktopPopupAlignmentDelegate::DesktopPopupAlignmentDelegate()
    : alignment_(POPUP_ALIGNMENT_BOTTOM | POPUP_ALIGNMENT_RIGHT),
      display_id_(gfx::Display::kInvalidDisplayID),
      screen_(NULL) {
}

DesktopPopupAlignmentDelegate::~DesktopPopupAlignmentDelegate() {
  if (screen_)
    screen_->RemoveObserver(this);
}

void DesktopPopupAlignmentDelegate::StartObserving(gfx::Screen* screen) {
  if (screen_ || !screen)
    return;

  screen_ = screen;
  screen_->AddObserver(this);
  gfx::Display display = screen_->GetPrimaryDisplay();
  display_id_ = display.id();
  RecomputeAlignment(display);
}

int DesktopPopupAlignmentDelegate::GetToastOriginX(
    const gfx::Rect& toast_bounds) const {
  if (IsFromLeft())
    return work_area_.x() + kMarginBetweenItems;
  return work_area_.right() - kMarginBetweenItems - toast_bounds.width();
}

int DesktopPopupAlignmentDelegate::GetBaseLine() const {
  return IsTopDown()
      ? work_area_.y() + kMarginBetweenItems
      : work_area_.bottom() - kMarginBetweenItems;
}

int DesktopPopupAlignmentDelegate::GetWorkAreaBottom() const {
  return work_area_.bottom();
}

bool DesktopPopupAlignmentDelegate::IsTopDown() const {
  return (alignment_ & POPUP_ALIGNMENT_TOP) != 0;
}

bool DesktopPopupAlignmentDelegate::IsFromLeft() const {
  return (alignment_ & POPUP_ALIGNMENT_LEFT) != 0;
}

void DesktopPopupAlignmentDelegate::RecomputeAlignment(
    const gfx::Display& display) {
  if (work_area_ == display.work_area())
    return;

  work_area_ = display.work_area();

  // If the taskbar is at the top, render notifications top down. Some platforms
  // like Gnome can have taskbars at top and bottom. In this case it's more
  // likely that the systray is on the top one.
  alignment_ = work_area_.y() > display.bounds().y() ? POPUP_ALIGNMENT_TOP
                                                     : POPUP_ALIGNMENT_BOTTOM;

  // If the taskbar is on the left show the notifications on the left. Otherwise
  // show it on right since it's very likely that the systray is on the right if
  // the taskbar is on the top or bottom.
  // Since on some platforms like Ubuntu Unity there's also a launcher along
  // with a taskbar (panel), we need to check that there is really nothing at
  // the top before concluding that the taskbar is at the left.
  alignment_ |= (work_area_.x() > display.bounds().x() &&
                 work_area_.y() == display.bounds().y())
      ? POPUP_ALIGNMENT_LEFT
      : POPUP_ALIGNMENT_RIGHT;
}

void DesktopPopupAlignmentDelegate::OnDisplayAdded(
    const gfx::Display& new_display) {
}

void DesktopPopupAlignmentDelegate::OnDisplayRemoved(
    const gfx::Display& old_display) {
}

void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged(
    const gfx::Display& display,
    uint32_t metrics) {
  if (display.id() == display_id_) {
    RecomputeAlignment(display);
    DoUpdateIfPossible();
  }
}

}  // namespace message_center