Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / gtk / download / download_shelf_gtk.h
1 // Copyright (c) 2012 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_GTK_DOWNLOAD_DOWNLOAD_SHELF_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_SHELF_GTK_H_
7
8 #include <gtk/gtk.h>
9
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "chrome/browser/download/download_shelf.h"
17 #include "chrome/browser/ui/gtk/slide_animator_gtk.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "ui/base/gtk/gtk_signal.h"
21 #include "ui/base/gtk/owned_widget_gtk.h"
22 #include "ui/gfx/native_widget_types.h"
23
24 class Browser;
25 class CustomDrawButton;
26 class DownloadItemGtk;
27 class GtkThemeService;
28
29 namespace content {
30 class PageNavigator;
31 }
32
33 namespace gfx {
34 class Point;
35 }
36
37 class DownloadShelfGtk : public DownloadShelf,
38                          public content::NotificationObserver,
39                          public SlideAnimatorGtk::Delegate,
40                          public base::MessageLoopForUI::Observer {
41  public:
42   DownloadShelfGtk(Browser* browser, gfx::NativeView view);
43
44   virtual ~DownloadShelfGtk();
45
46   // Retrieves the navigator for loading pages.
47   content::PageNavigator* GetNavigator();
48
49   // DownloadShelf implementation.
50   virtual bool IsShowing() const OVERRIDE;
51   virtual bool IsClosing() const OVERRIDE;
52   virtual Browser* browser() const OVERRIDE;
53
54   // SlideAnimatorGtk::Delegate implementation.
55   virtual void Closed() OVERRIDE;
56
57   // Overridden from content::NotificationObserver:
58   virtual void Observe(int type,
59                        const content::NotificationSource& source,
60                        const content::NotificationDetails& details) OVERRIDE;
61
62   // Returns the current height of the shelf.
63   int GetHeight() const;
64
65   // MessageLoop::Observer implementation:
66   virtual void WillProcessEvent(GdkEvent* event) OVERRIDE;
67   virtual void DidProcessEvent(GdkEvent* event) OVERRIDE;
68
69  protected:
70   // DownloadShelf implementation.
71   virtual void DoAddDownload(content::DownloadItem* download) OVERRIDE;
72   virtual void DoShow() OVERRIDE;
73   virtual void DoClose(CloseReason reason) OVERRIDE;
74
75  private:
76   // Remove |download_item| from the download shelf and delete it.
77   void RemoveDownloadItem(DownloadItemGtk* download_item);
78
79   // Get the hbox download items ought to pack themselves into.
80   GtkWidget* GetHBox() const;
81
82   // Show more hidden download items if there is enough space in the shelf.
83   // It's called when a download item is removed from the shelf or an item's
84   // size is changed.
85   void MaybeShowMoreDownloadItems();
86
87   // Checks that all download items have been opened, and sets the auto-close
88   // state of the shelf if so.
89   void AutoCloseIfPossible();
90
91   // Cancels the auto-close state set by AutoCloseIfPossible, including any
92   // pending close tasks that have already been posted.
93   void CancelAutoClose();
94
95   // A download item has been opened. It might be possible to automatically
96   // close now.
97   void ItemOpened();
98
99   // Sets whether the shelf should automatically close.
100   void SetCloseOnMouseOut(bool close);
101
102   // Returns whether the given point is within the "zone" of the shelf, which is
103   // the shelf and a band of 40 pixels on the top of it.
104   bool IsCursorInShelfZone(const gfx::Point& cursor_screen_coords);
105
106   // Synthesized enter-notify and leave-notify events for the shelf's "zone".
107   void MouseLeftShelf();
108   void MouseEnteredShelf();
109
110   CHROMEGTK_CALLBACK_0(DownloadShelfGtk, void, OnButtonClick);
111
112   // The browser that owns this download shelf.
113   Browser* browser_;
114
115   // The top level widget of the shelf.
116   scoped_ptr<SlideAnimatorGtk> slide_widget_;
117
118   // |items_hbox_| holds the download items.
119   ui::OwnedWidgetGtk items_hbox_;
120
121   // |shelf_| is the second highest level widget. See the constructor
122   // for an explanation of the widget layout.
123   ui::OwnedWidgetGtk shelf_;
124
125   // Top level event box which draws the one pixel border.
126   GtkWidget* top_border_;
127
128   // A GtkEventBox which we color.
129   GtkWidget* padding_bg_;
130
131   // The "Show all downloads..." link.
132   GtkWidget* link_button_;
133
134   // The 'x' that the user can press to hide the download shelf.
135   scoped_ptr<CustomDrawButton> close_button_;
136
137   // Keeps track of our current hide/show state.
138   bool is_showing_;
139
140   // The download items we have added to our shelf.
141   std::vector<DownloadItemGtk*> download_items_;
142
143   // Gives us our colors and theme information.
144   GtkThemeService* theme_service_;
145
146   content::NotificationRegistrar registrar_;
147
148   // True if the shelf will automatically close when the user mouses out.
149   bool close_on_mouse_out_;
150
151   // True if the mouse is within the shelf's bounds, as of the last mouse event
152   // we received.
153   bool mouse_in_shelf_;
154
155   base::WeakPtrFactory<DownloadShelfGtk> weak_factory_;
156
157   friend class DownloadItemGtk;
158 };
159
160 #endif  // CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_SHELF_GTK_H_