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