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

Side by Side Diff: chrome/browser/ui/views/status_bubble_views.cc

Issue 8301022: ui/views: Migrate usages of ScopedRunnableMethodFactory to base::WeakPtrFactory/base::Bind pair. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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
« no previous file with comments | « chrome/browser/ui/views/status_bubble_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/ui/views/status_bubble_views.h" 5 #include "chrome/browser/ui/views/status_bubble_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h"
9 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/themes/theme_service.h" 14 #include "chrome/browser/themes/theme_service.h"
14 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
15 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
17 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
18 #include "third_party/skia/include/core/SkPaint.h" 19 #include "third_party/skia/include/core/SkPaint.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 double GetCurrentOpacity(); 149 double GetCurrentOpacity();
149 void SetOpacity(double opacity); 150 void SetOpacity(double opacity);
150 void AnimateToState(double state); 151 void AnimateToState(double state);
151 void AnimationEnded(const Animation* animation); 152 void AnimationEnded(const Animation* animation);
152 153
153 virtual void OnPaint(gfx::Canvas* canvas); 154 virtual void OnPaint(gfx::Canvas* canvas);
154 155
155 BubbleStage stage_; 156 BubbleStage stage_;
156 BubbleStyle style_; 157 BubbleStyle style_;
157 158
158 ScopedRunnableMethodFactory<StatusBubbleViews::StatusView> timer_factory_; 159 base::WeakPtrFactory<StatusBubbleViews::StatusView> timer_factory_;
159 160
160 // Manager, owns us. 161 // Manager, owns us.
161 StatusBubble* status_bubble_; 162 StatusBubble* status_bubble_;
162 163
163 // Handle to the widget that contains us. 164 // Handle to the widget that contains us.
164 views::Widget* popup_; 165 views::Widget* popup_;
165 166
166 // The currently-displayed text. 167 // The currently-displayed text.
167 string16 text_; 168 string16 text_;
168 169
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 void StatusBubbleViews::StatusView::Hide() { 203 void StatusBubbleViews::StatusView::Hide() {
203 Stop(); 204 Stop();
204 CancelTimer(); 205 CancelTimer();
205 SetOpacity(0.0); 206 SetOpacity(0.0);
206 text_.clear(); 207 text_.clear();
207 popup_->Hide(); 208 popup_->Hide();
208 stage_ = BUBBLE_HIDDEN; 209 stage_ = BUBBLE_HIDDEN;
209 } 210 }
210 211
211 void StatusBubbleViews::StatusView::StartTimer(int time) { 212 void StatusBubbleViews::StatusView::StartTimer(int time) {
212 if (!timer_factory_.empty()) 213 if (timer_factory_.HasWeakPtrs())
213 timer_factory_.RevokeAll(); 214 timer_factory_.InvalidateWeakPtrs();
214 215
215 MessageLoop::current()->PostDelayedTask(FROM_HERE, 216 MessageLoop::current()->PostDelayedTask(
216 timer_factory_.NewRunnableMethod(&StatusBubbleViews::StatusView::OnTimer), 217 FROM_HERE,
218 base::Bind(&StatusBubbleViews::StatusView::OnTimer,
219 timer_factory_.GetWeakPtr()),
217 time); 220 time);
218 } 221 }
219 222
220 void StatusBubbleViews::StatusView::OnTimer() { 223 void StatusBubbleViews::StatusView::OnTimer() {
221 if (stage_ == BUBBLE_HIDING_TIMER) { 224 if (stage_ == BUBBLE_HIDING_TIMER) {
222 stage_ = BUBBLE_HIDING_FADE; 225 stage_ = BUBBLE_HIDING_FADE;
223 StartFade(1.0, 0.0, kHideFadeDurationMS); 226 StartFade(1.0, 0.0, kHideFadeDurationMS);
224 } else if (stage_ == BUBBLE_SHOWING_TIMER) { 227 } else if (stage_ == BUBBLE_SHOWING_TIMER) {
225 stage_ = BUBBLE_SHOWING_FADE; 228 stage_ = BUBBLE_SHOWING_FADE;
226 StartFade(0.0, 1.0, kShowFadeDurationMS); 229 StartFade(0.0, 1.0, kShowFadeDurationMS);
227 } 230 }
228 } 231 }
229 232
230 void StatusBubbleViews::StatusView::CancelTimer() { 233 void StatusBubbleViews::StatusView::CancelTimer() {
231 if (!timer_factory_.empty()) 234 if (timer_factory_.HasWeakPtrs())
232 timer_factory_.RevokeAll(); 235 timer_factory_.InvalidateWeakPtrs();
233 } 236 }
234 237
235 void StatusBubbleViews::StatusView::RestartTimer(int delay) { 238 void StatusBubbleViews::StatusView::RestartTimer(int delay) {
236 CancelTimer(); 239 CancelTimer();
237 StartTimer(delay); 240 StartTimer(delay);
238 } 241 }
239 242
240 void StatusBubbleViews::StatusView::ResetTimer() { 243 void StatusBubbleViews::StatusView::ResetTimer() {
241 if (stage_ == BUBBLE_SHOWING_TIMER) { 244 if (stage_ == BUBBLE_SHOWING_TIMER) {
242 // We hadn't yet begun showing anything when we received a new request 245 // We hadn't yet begun showing anything when we received a new request
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 if (IsFrameVisible()) { 664 if (IsFrameVisible()) {
662 view_->SetText(url_text_, true); 665 view_->SetText(url_text_, true);
663 666
664 CancelExpandTimer(); 667 CancelExpandTimer();
665 668
666 // If bubble is already in expanded state, shift to adjust to new text 669 // If bubble is already in expanded state, shift to adjust to new text
667 // size (shrinking or expanding). Otherwise delay. 670 // size (shrinking or expanding). Otherwise delay.
668 if (is_expanded_ && !url.is_empty()) 671 if (is_expanded_ && !url.is_empty())
669 ExpandBubble(); 672 ExpandBubble();
670 else if (original_url_text.length() > url_text_.length()) 673 else if (original_url_text.length() > url_text_.length())
671 MessageLoop::current()->PostDelayedTask(FROM_HERE, 674 MessageLoop::current()->PostDelayedTask(
672 expand_timer_factory_.NewRunnableMethod( 675 FROM_HERE,
673 &StatusBubbleViews::ExpandBubble), kExpandHoverDelay); 676 base::Bind(&StatusBubbleViews::ExpandBubble,
677 expand_timer_factory_.GetWeakPtr()),
678 kExpandHoverDelay);
674 } 679 }
675 } 680 }
676 681
677 void StatusBubbleViews::Hide() { 682 void StatusBubbleViews::Hide() {
678 status_text_ = string16(); 683 status_text_ = string16();
679 url_text_ = string16(); 684 url_text_ = string16();
680 if (view_) 685 if (view_)
681 view_->Hide(); 686 view_->Hide();
682 } 687 }
683 688
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 views::NativeScrollBar::GetVerticalScrollBarWidth())); 828 views::NativeScrollBar::GetVerticalScrollBarWidth()));
824 } 829 }
825 830
826 void StatusBubbleViews::SetBubbleWidth(int width) { 831 void StatusBubbleViews::SetBubbleWidth(int width) {
827 size_.set_width(width); 832 size_.set_width(width);
828 SetBounds(original_position_.x(), original_position_.y(), 833 SetBounds(original_position_.x(), original_position_.y(),
829 size_.width(), size_.height()); 834 size_.width(), size_.height());
830 } 835 }
831 836
832 void StatusBubbleViews::CancelExpandTimer() { 837 void StatusBubbleViews::CancelExpandTimer() {
833 if (!expand_timer_factory_.empty()) 838 if (expand_timer_factory_.HasWeakPtrs())
834 expand_timer_factory_.RevokeAll(); 839 expand_timer_factory_.InvalidateWeakPtrs();
835 } 840 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/status_bubble_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698