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

Side by Side Diff: chrome/browser/ui/views/download/download_started_animation_views.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: Merged with ToT 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 "content/public/browser/notification_details.h" 7 #include "content/public/browser/notification_details.h"
8 #include "content/public/browser/notification_observer.h" 8 #include "content/public/browser/notification_observer.h"
9 #include "content/public/browser/notification_registrar.h" 9 #include "content/public/browser/notification_registrar.h"
10 #include "content/public/browser/notification_source.h" 10 #include "content/public/browser/notification_source.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 // If we're too small to show the download image, then don't bother - 91 // If we're too small to show the download image, then don't bother -
92 // the shelf will be enough. 92 // the shelf will be enough.
93 web_contents_->GetContainerBounds(&web_contents_bounds_); 93 web_contents_->GetContainerBounds(&web_contents_bounds_);
94 if (web_contents_bounds_.height() < kDownloadImage->height()) 94 if (web_contents_bounds_.height() < kDownloadImage->height())
95 return; 95 return;
96 96
97 registrar_.Add( 97 registrar_.Add(
98 this, 98 this,
99 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, 99 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
100 content::Source<WebContents>(web_contents_)); 100 content::Source<WebContents>(web_contents_));
101 registrar_.Add( 101 registrar_.Add(
102 this, 102 this,
103 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 103 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
104 content::Source<WebContents>(web_contents_)); 104 content::Source<WebContents>(web_contents_));
105 105
106 SetImage(kDownloadImage); 106 SetImage(kDownloadImage);
107 107
108 popup_ = new views::Widget; 108 popup_ = new views::Widget;
109 109
(...skipping 26 matching lines...) Expand all
136 size.width(), 136 size.width(),
137 size.height())); 137 size.height()));
138 } 138 }
139 139
140 void DownloadStartedAnimationWin::Close() { 140 void DownloadStartedAnimationWin::Close() {
141 if (!web_contents_) 141 if (!web_contents_)
142 return; 142 return;
143 143
144 registrar_.Remove( 144 registrar_.Remove(
145 this, 145 this,
146 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, 146 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
147 content::Source<WebContents>(web_contents_)); 147 content::Source<WebContents>(web_contents_));
148 registrar_.Remove( 148 registrar_.Remove(
149 this, 149 this,
150 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 150 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
151 content::Source<WebContents>(web_contents_)); 151 content::Source<WebContents>(web_contents_));
152 web_contents_ = NULL; 152 web_contents_ = NULL;
153 popup_->Close(); 153 popup_->Close();
154 } 154 }
155 155
156 void DownloadStartedAnimationWin::AnimateToState(double state) { 156 void DownloadStartedAnimationWin::AnimateToState(double state) {
157 if (state >= 1.0) { 157 if (state >= 1.0) {
158 Close(); 158 Close();
159 } else { 159 } else {
160 Reposition(); 160 Reposition();
161 161
162 // Start at zero, peak halfway and end at zero. 162 // Start at zero, peak halfway and end at zero.
163 double opacity = std::min(1.0 - pow(GetCurrentValue() - 0.5, 2) * 4.0, 163 double opacity = std::min(1.0 - pow(GetCurrentValue() - 0.5, 2) * 4.0,
164 static_cast<double>(1.0)); 164 static_cast<double>(1.0));
165 165
166 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255.0)); 166 popup_->SetOpacity(static_cast<unsigned char>(opacity * 255.0));
167 } 167 }
168 } 168 }
169 169
170 void DownloadStartedAnimationWin::Observe( 170 void DownloadStartedAnimationWin::Observe(
171 int type, 171 int type,
172 const content::NotificationSource& source, 172 const content::NotificationSource& source,
173 const content::NotificationDetails& details) { 173 const content::NotificationDetails& details) {
174 if (type == content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED) {
175 bool visible = *content::Details<bool>(details).ptr();
176 if (visible)
177 return;
178 }
174 Close(); 179 Close();
175 } 180 }
176 181
177 } // namespace 182 } // namespace
178 183
179 // static 184 // static
180 void DownloadStartedAnimation::Show(WebContents* web_contents) { 185 void DownloadStartedAnimation::Show(WebContents* web_contents) {
181 // The animation will delete itself when it's finished or when the tab 186 // The animation will delete itself when it's finished or when the tab
182 // contents is hidden or destroyed. 187 // contents is hidden or destroyed.
183 new DownloadStartedAnimationWin(web_contents); 188 new DownloadStartedAnimationWin(web_contents);
184 } 189 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/download/download_started_animation_gtk.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698