message_center_widget_delegate.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_MESSAGE_CENTER_WIDGET_DELEGATE_H_
6#define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_MESSAGE_CENTER_WIDGET_DELEGATE_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "base/memory/weak_ptr.h"
11#include "base/strings/string16.h"
12#include "ui/gfx/point.h"
13#include "ui/gfx/rect.h"
14#include "ui/message_center/message_center.h"
15#include "ui/message_center/message_center_tray.h"
16#include "ui/message_center/message_center_tray_delegate.h"
17#include "ui/message_center/views/message_center_view.h"
18#include "ui/views/widget/widget_delegate.h"
19#include "ui/views/widget/widget_observer.h"
20
21namespace message_center {
22
23enum Alignment {
24  ALIGNMENT_TOP = 1 << 0,
25  ALIGNMENT_LEFT = 1 << 1,
26  ALIGNMENT_BOTTOM = 1 << 2,
27  ALIGNMENT_RIGHT = 1 << 3,
28  ALIGNMENT_NONE = 1 << 4,
29};
30
31struct PositionInfo {
32  int max_height;
33
34  // Alignment of the message center relative to the center of the screen.
35  Alignment message_center_alignment;
36
37  // Alignment of the taskbar relative to the center of the screen.
38  Alignment taskbar_alignment;
39
40  // Point relative to which message center is positioned.
41  gfx::Point inital_anchor_point;
42};
43
44class WebNotificationTray;
45class MessageCenterFrameView;
46
47// MessageCenterWidgetDelegate is the message center's client view. It also
48// creates the message center widget and sets the notifications.
49//
50////////////////////////////////////////////////////////////////////////////////
51class MessageCenterWidgetDelegate : public views::WidgetDelegate,
52                                    public message_center::MessageCenterView,
53                                    public views::WidgetObserver {
54 public:
55  MessageCenterWidgetDelegate(WebNotificationTray* tray,
56                              MessageCenterTray* mc_tray,
57                              bool initially_settings_visible,
58                              const PositionInfo& pos_info,
59                              const base::string16& title);
60  virtual ~MessageCenterWidgetDelegate();
61
62  // WidgetDelegate overrides:
63  virtual View* GetContentsView() OVERRIDE;
64  virtual views::NonClientFrameView* CreateNonClientFrameView(
65      views::Widget* widget) OVERRIDE;
66  virtual void DeleteDelegate() OVERRIDE;
67  virtual views::Widget* GetWidget() OVERRIDE;
68  virtual const views::Widget* GetWidget() const OVERRIDE;
69
70  // WidgetObserver overrides:
71  virtual void OnWidgetActivationChanged(views::Widget* widget,
72                                         bool active) OVERRIDE;
73  virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
74
75  // View overrides:
76  virtual void PreferredSizeChanged() OVERRIDE;
77  virtual gfx::Size GetPreferredSize() const OVERRIDE;
78  virtual gfx::Size GetMaximumSize() const OVERRIDE;
79  virtual int GetHeightForWidth(int width) const OVERRIDE;
80  virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
81
82 private:
83  // Creates and initializes the message center widget.
84  void InitWidget();
85
86  // Shifts the message center anchor point such that the mouse click point is
87  // along the middle 60% of the width of the message center if taskbar is
88  // horizontal aligned. If vertically aligned, ensures that mouse click point
89  // is along the height of the message center (at least at a corner).
90  gfx::Point GetCorrectedAnchor(gfx::Size calculated_size);
91
92  // Calculates the message center bounds using the position info and the
93  // corrected anchor.
94  gfx::Rect GetMessageCenterBounds();
95
96  // Insets of the message center border (set in MessageCenterFrameView).
97  gfx::Insets border_insets_;
98
99  // Info necessary to calculate the estimated position of the message center.
100  PositionInfo pos_info_;
101
102  WebNotificationTray* tray_;
103};
104
105}  // namespace message_center
106
107#endif  // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_MESSAGE_CENTER_WIDGET_DELEGATE_H_
108