Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1380)

Side by Side Diff: chrome/browser/ui/gtk/download/download_started_animation_gtk.cc

Issue 10411033: Browser Plugin: WebContents should notify when it's restored (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed a test DCHECK Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/download/download_started_animation.h" 5 #include "chrome/browser/download/download_started_animation.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 10
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "content/public/browser/notification_details.h"
12 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
18 #include "ui/base/animation/linear_animation.h" 19 #include "ui/base/animation/linear_animation.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 height_ = gdk_pixbuf_get_height(kDownloadImage); 100 height_ = gdk_pixbuf_get_height(kDownloadImage);
100 101
101 // If we're too small to show the download image, then don't bother - 102 // If we're too small to show the download image, then don't bother -
102 // the shelf will be enough. 103 // the shelf will be enough.
103 web_contents_->GetContainerBounds(&web_contents_bounds_); 104 web_contents_->GetContainerBounds(&web_contents_bounds_);
104 if (web_contents_bounds_.height() < height_) 105 if (web_contents_bounds_.height() < height_)
105 return; 106 return;
106 107
107 registrar_.Add( 108 registrar_.Add(
108 this, 109 this,
109 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, 110 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
110 content::Source<WebContents>(web_contents_)); 111 content::Source<WebContents>(web_contents_));
111 registrar_.Add( 112 registrar_.Add(
112 this, 113 this,
113 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 114 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
114 content::Source<WebContents>(web_contents_)); 115 content::Source<WebContents>(web_contents_));
115 116
116 // TODO(estade): don't show up on the wrong virtual desktop. 117 // TODO(estade): don't show up on the wrong virtual desktop.
117 118
118 popup_ = gtk_window_new(GTK_WINDOW_POPUP); 119 popup_ = gtk_window_new(GTK_WINDOW_POPUP);
119 GtkWidget* image = gtk_image_new_from_pixbuf(kDownloadImage); 120 GtkWidget* image = gtk_image_new_from_pixbuf(kDownloadImage);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 156 }
156 157
157 void DownloadStartedAnimationGtk::Close() { 158 void DownloadStartedAnimationGtk::Close() {
158 if (!web_contents_) 159 if (!web_contents_)
159 return; 160 return;
160 161
161 DCHECK(popup_); 162 DCHECK(popup_);
162 163
163 registrar_.Remove( 164 registrar_.Remove(
164 this, 165 this,
165 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, 166 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
166 content::Source<WebContents>(web_contents_)); 167 content::Source<WebContents>(web_contents_));
167 registrar_.Remove( 168 registrar_.Remove(
168 this, 169 this,
169 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 170 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
170 content::Source<WebContents>(web_contents_)); 171 content::Source<WebContents>(web_contents_));
171 172
172 web_contents_ = NULL; 173 web_contents_ = NULL;
173 gtk_widget_destroy(popup_); 174 gtk_widget_destroy(popup_);
174 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 175 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
175 } 176 }
(...skipping 13 matching lines...) Expand all
189 190
190 // This only works when there's a compositing manager running. Oh well. 191 // This only works when there's a compositing manager running. Oh well.
191 gtk_window_set_opacity(GTK_WINDOW(popup_), opacity); 192 gtk_window_set_opacity(GTK_WINDOW(popup_), opacity);
192 } 193 }
193 } 194 }
194 195
195 void DownloadStartedAnimationGtk::Observe( 196 void DownloadStartedAnimationGtk::Observe(
196 int type, 197 int type,
197 const content::NotificationSource& source, 198 const content::NotificationSource& source,
198 const content::NotificationDetails& details) { 199 const content::NotificationDetails& details) {
200 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
201 bool visible = *content::Details<bool>(details).ptr();
202 if (visible)
203 return;
204 }
199 Close(); 205 Close();
200 } 206 }
201 207
202 } // namespace 208 } // namespace
203 209
204 // static 210 // static
205 void DownloadStartedAnimation::Show(WebContents* web_contents) { 211 void DownloadStartedAnimation::Show(WebContents* web_contents) {
206 // The animation will delete itself. 212 // The animation will delete itself.
207 new DownloadStartedAnimationGtk(web_contents); 213 new DownloadStartedAnimationGtk(web_contents);
208 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698