Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / download / download_shelf_gtk.h
blobeffadcaad58d726870a21e1e6cb7fb7bf731052a
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.
5 #ifndef CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_SHELF_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_SHELF_GTK_H_
8 #include <gtk/gtk.h>
10 #include <vector>
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"
24 class Browser;
25 class CustomDrawButton;
26 class DownloadItemGtk;
27 class GtkThemeService;
29 namespace content {
30 class PageNavigator;
33 namespace gfx {
34 class Point;
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);
44 virtual ~DownloadShelfGtk();
46 // Retrieves the navigator for loading pages.
47 content::PageNavigator* GetNavigator();
49 // DownloadShelf implementation.
50 virtual bool IsShowing() const OVERRIDE;
51 virtual bool IsClosing() const OVERRIDE;
52 virtual Browser* browser() const OVERRIDE;
54 // SlideAnimatorGtk::Delegate implementation.
55 virtual void Closed() OVERRIDE;
57 // Overridden from content::NotificationObserver:
58 virtual void Observe(int type,
59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) OVERRIDE;
62 // Returns the current height of the shelf.
63 int GetHeight() const;
65 // MessageLoop::Observer implementation:
66 virtual void WillProcessEvent(GdkEvent* event) OVERRIDE;
67 virtual void DidProcessEvent(GdkEvent* event) OVERRIDE;
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;
75 private:
76 // Remove |download_item| from the download shelf and delete it.
77 void RemoveDownloadItem(DownloadItemGtk* download_item);
79 // Get the hbox download items ought to pack themselves into.
80 GtkWidget* GetHBox() const;
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();
87 // Checks that all download items have been opened, and sets the auto-close
88 // state of the shelf if so.
89 void AutoCloseIfPossible();
91 // Cancels the auto-close state set by AutoCloseIfPossible, including any
92 // pending close tasks that have already been posted.
93 void CancelAutoClose();
95 // A download item has been opened. It might be possible to automatically
96 // close now.
97 void ItemOpened();
99 // Sets whether the shelf should automatically close.
100 void SetCloseOnMouseOut(bool close);
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);
106 // Synthesized enter-notify and leave-notify events for the shelf's "zone".
107 void MouseLeftShelf();
108 void MouseEnteredShelf();
110 CHROMEGTK_CALLBACK_0(DownloadShelfGtk, void, OnButtonClick);
112 // The browser that owns this download shelf.
113 Browser* browser_;
115 // The top level widget of the shelf.
116 scoped_ptr<SlideAnimatorGtk> slide_widget_;
118 // |items_hbox_| holds the download items.
119 ui::OwnedWidgetGtk items_hbox_;
121 // |shelf_| is the second highest level widget. See the constructor
122 // for an explanation of the widget layout.
123 ui::OwnedWidgetGtk shelf_;
125 // Top level event box which draws the one pixel border.
126 GtkWidget* top_border_;
128 // A GtkEventBox which we color.
129 GtkWidget* padding_bg_;
131 // The "Show all downloads..." link.
132 GtkWidget* link_button_;
134 // The 'x' that the user can press to hide the download shelf.
135 scoped_ptr<CustomDrawButton> close_button_;
137 // Keeps track of our current hide/show state.
138 bool is_showing_;
140 // The download items we have added to our shelf.
141 std::vector<DownloadItemGtk*> download_items_;
143 // Gives us our colors and theme information.
144 GtkThemeService* theme_service_;
146 content::NotificationRegistrar registrar_;
148 // True if the shelf will automatically close when the user mouses out.
149 bool close_on_mouse_out_;
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_;
155 base::WeakPtrFactory<DownloadShelfGtk> weak_factory_;
157 friend class DownloadItemGtk;
160 #endif // CHROME_BROWSER_UI_GTK_DOWNLOAD_DOWNLOAD_SHELF_GTK_H_