OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_GTK_DOWNLOAD_SHELF_GTK_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_DOWNLOAD_SHELF_GTK_H_ |
6 #define CHROME_BROWSER_UI_GTK_DOWNLOAD_SHELF_GTK_H_ | 6 #define CHROME_BROWSER_UI_GTK_DOWNLOAD_SHELF_GTK_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/message_loop.h" |
13 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
14 #include "chrome/browser/download/download_shelf.h" | 15 #include "chrome/browser/download/download_shelf.h" |
15 #include "chrome/browser/ui/gtk/owned_widget_gtk.h" | 16 #include "chrome/browser/ui/gtk/owned_widget_gtk.h" |
16 #include "chrome/browser/ui/gtk/slide_animator_gtk.h" | 17 #include "chrome/browser/ui/gtk/slide_animator_gtk.h" |
17 #include "chrome/common/notification_observer.h" | 18 #include "chrome/common/notification_observer.h" |
18 #include "chrome/common/notification_registrar.h" | 19 #include "chrome/common/notification_registrar.h" |
19 #include "gfx/native_widget_types.h" | 20 #include "gfx/native_widget_types.h" |
20 #include "ui/base/gtk/gtk_signal.h" | 21 #include "ui/base/gtk/gtk_signal.h" |
21 | 22 |
22 class BaseDownloadItemModel; | 23 class BaseDownloadItemModel; |
23 class Browser; | 24 class Browser; |
24 class CustomDrawButton; | 25 class CustomDrawButton; |
25 class DownloadItemGtk; | 26 class DownloadItemGtk; |
26 class GtkThemeProvider; | 27 class GtkThemeProvider; |
27 class SlideAnimatorGtk; | 28 class SlideAnimatorGtk; |
28 | 29 |
| 30 namespace gfx { |
| 31 class Point; |
| 32 } |
| 33 |
29 class DownloadShelfGtk : public DownloadShelf, | 34 class DownloadShelfGtk : public DownloadShelf, |
30 public NotificationObserver, | 35 public NotificationObserver, |
31 public SlideAnimatorGtk::Delegate { | 36 public SlideAnimatorGtk::Delegate, |
| 37 public MessageLoopForUI::Observer { |
32 public: | 38 public: |
33 explicit DownloadShelfGtk(Browser* browser, gfx::NativeView view); | 39 explicit DownloadShelfGtk(Browser* browser, gfx::NativeView view); |
34 | 40 |
35 ~DownloadShelfGtk(); | 41 ~DownloadShelfGtk(); |
36 | 42 |
37 // DownloadShelf implementation. | 43 // DownloadShelf implementation. |
38 virtual void AddDownload(BaseDownloadItemModel* download_model); | 44 virtual void AddDownload(BaseDownloadItemModel* download_model); |
39 virtual bool IsShowing() const; | 45 virtual bool IsShowing() const; |
40 virtual bool IsClosing() const; | 46 virtual bool IsClosing() const; |
41 virtual void Show(); | 47 virtual void Show(); |
42 virtual void Close(); | 48 virtual void Close(); |
43 virtual Browser* browser() const; | 49 virtual Browser* browser() const; |
44 | 50 |
45 // SlideAnimatorGtk::Delegate implementation. | 51 // SlideAnimatorGtk::Delegate implementation. |
46 virtual void Closed(); | 52 virtual void Closed(); |
47 | 53 |
48 // Overridden from NotificationObserver: | 54 // Overridden from NotificationObserver: |
49 virtual void Observe(NotificationType type, | 55 virtual void Observe(NotificationType type, |
50 const NotificationSource& source, | 56 const NotificationSource& source, |
51 const NotificationDetails& details); | 57 const NotificationDetails& details); |
52 | 58 |
53 // Returns the current height of the shelf. | 59 // Returns the current height of the shelf. |
54 int GetHeight() const; | 60 int GetHeight() const; |
55 | 61 |
| 62 // MessageLoop::Observer implementation: |
| 63 virtual void WillProcessEvent(GdkEvent* event); |
| 64 virtual void DidProcessEvent(GdkEvent* event); |
| 65 |
56 private: | 66 private: |
57 // Remove |download_item| from the download shelf and delete it. | 67 // Remove |download_item| from the download shelf and delete it. |
58 void RemoveDownloadItem(DownloadItemGtk* download_item); | 68 void RemoveDownloadItem(DownloadItemGtk* download_item); |
59 | 69 |
60 // Get the hbox download items ought to pack themselves into. | 70 // Get the hbox download items ought to pack themselves into. |
61 GtkWidget* GetHBox() const; | 71 GtkWidget* GetHBox() const; |
62 | 72 |
63 // Show more hidden download items if there is enough space in the shelf. | 73 // Show more hidden download items if there is enough space in the shelf. |
64 // It's called when a download item is removed from the shelf or an item's | 74 // It's called when a download item is removed from the shelf or an item's |
65 // size is changed. | 75 // size is changed. |
66 void MaybeShowMoreDownloadItems(); | 76 void MaybeShowMoreDownloadItems(); |
67 | 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 |
68 CHROMEGTK_CALLBACK_0(DownloadShelfGtk, void, OnButtonClick); | 101 CHROMEGTK_CALLBACK_0(DownloadShelfGtk, void, OnButtonClick); |
69 | 102 |
70 // The browser that owns this download shelf. | 103 // The browser that owns this download shelf. |
71 Browser* browser_; | 104 Browser* browser_; |
72 | 105 |
73 // The top level widget of the shelf. | 106 // The top level widget of the shelf. |
74 scoped_ptr<SlideAnimatorGtk> slide_widget_; | 107 scoped_ptr<SlideAnimatorGtk> slide_widget_; |
75 | 108 |
76 // |items_hbox_| holds the download items. | 109 // |items_hbox_| holds the download items. |
77 OwnedWidgetGtk items_hbox_; | 110 OwnedWidgetGtk items_hbox_; |
(...skipping 18 matching lines...) Expand all Loading... |
96 bool is_showing_; | 129 bool is_showing_; |
97 | 130 |
98 // The download items we have added to our shelf. | 131 // The download items we have added to our shelf. |
99 std::vector<DownloadItemGtk*> download_items_; | 132 std::vector<DownloadItemGtk*> download_items_; |
100 | 133 |
101 // Gives us our colors and theme information. | 134 // Gives us our colors and theme information. |
102 GtkThemeProvider* theme_provider_; | 135 GtkThemeProvider* theme_provider_; |
103 | 136 |
104 NotificationRegistrar registrar_; | 137 NotificationRegistrar registrar_; |
105 | 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 |
106 friend class DownloadItemGtk; | 148 friend class DownloadItemGtk; |
107 }; | 149 }; |
108 | 150 |
109 #endif // CHROME_BROWSER_UI_GTK_DOWNLOAD_SHELF_GTK_H_ | 151 #endif // CHROME_BROWSER_UI_GTK_DOWNLOAD_SHELF_GTK_H_ |
OLD | NEW |