- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / message_center / message_center_widget_delegate.h
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 "chrome/browser/ui/views/message_center/web_notification_tray.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
21 namespace message_center {
22
23 enum 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
31 struct 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
44 class WebNotificationTray;
45 class 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 ////////////////////////////////////////////////////////////////////////////////
51 class 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   virtual ~MessageCenterWidgetDelegate();
60
61   // WidgetDelegate overrides:
62   virtual View* GetContentsView() OVERRIDE;
63   virtual views::NonClientFrameView* CreateNonClientFrameView(
64       views::Widget* widget) OVERRIDE;
65   virtual void DeleteDelegate() OVERRIDE;
66   virtual views::Widget* GetWidget() OVERRIDE;
67   virtual const views::Widget* GetWidget() const OVERRIDE;
68
69   // WidgetObserver overrides:
70   virtual void OnWidgetActivationChanged(views::Widget* widget,
71                                          bool active) OVERRIDE;
72   virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
73
74   // View overrides:
75   virtual void PreferredSizeChanged() OVERRIDE;
76   virtual gfx::Size GetPreferredSize() OVERRIDE;
77   virtual gfx::Size GetMaximumSize() OVERRIDE;
78   virtual int GetHeightForWidth(int width) OVERRIDE;
79   virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
80
81  private:
82   // Creates and initializes the message center widget.
83   void InitWidget();
84
85   // Shifts the message center anchor point such that the mouse click point is
86   // along the middle 60% of the width of the message center if taskbar is
87   // horizontal aligned. If vertically aligned, ensures that mouse click point
88   // is along the height of the message center (at least at a corner).
89   gfx::Point GetCorrectedAnchor(gfx::Size calculated_size);
90
91   // Calculates the message center bounds using the position info and the
92   // corrected anchor.
93   gfx::Rect GetMessageCenterBounds();
94
95   // Insets of the message center border (set in MessageCenterFrameView).
96   gfx::Insets border_insets_;
97
98   // Info necessary to calculate the estimated position of the message center.
99   PositionInfo pos_info_;
100
101   WebNotificationTray* tray_;
102 };
103
104 }  // namespace message_center
105
106 #endif  // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_MESSAGE_CENTER_WIDGET_DELEGATE_H_