Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/login/helper.h" | 5 #include "chrome/browser/chromeos/login/helper.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "chrome/browser/google/google_util.h" | 8 #include "chrome/browser/google/google_util.h" |
| 9 #include "gfx/canvas_skia.h" | 9 #include "gfx/canvas_skia.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
| 12 #include "third_party/skia/include/effects/SkGradientShader.h" | 12 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 13 #include "views/controls/button/menu_button.h" | 13 #include "views/controls/button/menu_button.h" |
| 14 #include "views/controls/button/native_button.h" | 14 #include "views/controls/button/native_button.h" |
| 15 #include "views/controls/label.h" | 15 #include "views/controls/label.h" |
| 16 #include "views/controls/textfield/textfield.h" | 16 #include "views/controls/textfield/textfield.h" |
| 17 #include "views/controls/throbber.h" | 17 #include "views/controls/throbber.h" |
| 18 #include "views/painter.h" | 18 #include "views/painter.h" |
| 19 #include "views/screen.h" | 19 #include "views/screen.h" |
| 20 #include "views/widget/widget.h" | |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Time in ms per throbber frame. | 26 // Time in ms per throbber frame. |
| 26 const int kThrobberFrameMs = 60; | 27 const int kThrobberFrameMs = 60; |
| 27 | 28 |
| 28 // Time in ms before smoothed throbber is shown. | 29 // Time in ms before smoothed throbber is shown. |
| 29 const int kThrobberStartDelayMs = 500; | 30 const int kThrobberStartDelayMs = 500; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 60 s->unref(); | 61 s->unref(); |
| 61 canvas->AsCanvasSkia()->drawRect(rect, paint); | 62 canvas->AsCanvasSkia()->drawRect(rect, paint); |
| 62 } | 63 } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); | 66 DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 71 ThrobberManager::ThrobberManager() : throbber_widget_(NULL) { | |
| 72 } | |
| 73 | |
| 74 ThrobberManager::~ThrobberManager() { | |
| 75 Stop(); | |
| 76 } | |
| 77 | |
| 78 void ThrobberManager::StartShow(views::Widget* host, | |
| 79 views::Throbber* throbber, | |
| 80 int right_shift) { | |
| 81 if (throbber_widget_) { | |
| 82 delete throbber; | |
| 83 return; | |
|
whywhat
2010/12/09 16:20:18
Shouldn't this be a check? Also, why delete throbb
altimofeev
2010/12/10 16:37:40
Changed the behavior. Now, previously created thro
| |
| 84 } | |
| 85 | |
| 86 gfx::Rect host_bounds; | |
| 87 host->GetBounds(&host_bounds, false); | |
| 88 gfx::Rect bounds(throbber->GetPreferredSize()); | |
| 89 bounds.set_x(host_bounds.width() - right_shift - bounds.width()); | |
| 90 bounds.set_y((host_bounds.height() - bounds.height()) / 2); | |
| 91 StartShow(host, throbber, bounds); | |
| 92 } | |
| 93 | |
| 94 void ThrobberManager::StartShow(views::Widget* host, | |
| 95 views::Throbber* throbber, | |
| 96 const gfx::Rect relative_bounds) { | |
| 97 if (throbber_widget_) { | |
| 98 delete throbber; | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 throbber_widget_ = | |
| 103 views::Widget::CreatePopupWidget(views::Widget::Transparent, | |
| 104 views::Widget::NotAcceptEvents, | |
| 105 views::Widget::DeleteOnDestroy, | |
| 106 views::Widget::DontMirrorOriginInRTL); | |
| 107 gfx::Rect host_bounds; | |
| 108 host->GetBounds(&host_bounds, false); | |
| 109 gfx::Rect bounds = relative_bounds; | |
| 110 bounds.Offset(host_bounds.origin()); | |
| 111 throbber_widget_->InitWithWidget(host, bounds); | |
| 112 throbber_widget_->SetContentsView(throbber); | |
| 113 throbber_widget_->Show(); | |
| 114 throbber->Start(); | |
| 115 } | |
| 116 | |
| 117 void ThrobberManager::Stop() { | |
| 118 if (throbber_widget_) { | |
| 119 throbber_widget_->Close(); | |
|
whywhat
2010/12/09 16:20:18
So we delete it in Start, but Close in Stop? Why t
altimofeev
2010/12/10 16:37:40
In Start we have been deleting |throbber| which wa
| |
| 120 throbber_widget_ = NULL; | |
| 121 } | |
| 122 } | |
| 123 | |
| 70 views::Throbber* CreateDefaultSmoothedThrobber() { | 124 views::Throbber* CreateDefaultSmoothedThrobber() { |
| 71 views::SmoothedThrobber* throbber = | 125 views::SmoothedThrobber* throbber = |
| 72 new views::SmoothedThrobber(kThrobberFrameMs); | 126 new views::SmoothedThrobber(kThrobberFrameMs); |
| 73 throbber->SetFrames( | 127 throbber->SetFrames( |
| 74 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); | 128 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); |
| 75 throbber->set_start_delay_ms(kThrobberStartDelayMs); | 129 throbber->set_start_delay_ms(kThrobberStartDelayMs); |
| 76 return throbber; | 130 return throbber; |
| 77 } | 131 } |
| 78 | 132 |
| 79 views::Throbber* CreateDefaultThrobber() { | 133 views::Throbber* CreateDefaultThrobber() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 gfx::Size preferred_size = NativeButton::GetPreferredSize(); | 185 gfx::Size preferred_size = NativeButton::GetPreferredSize(); |
| 132 // Set minimal width. | 186 // Set minimal width. |
| 133 if (preferred_size.width() < kButtonMinWidth) | 187 if (preferred_size.width() < kButtonMinWidth) |
| 134 preferred_size.set_width(kButtonMinWidth); | 188 preferred_size.set_width(kButtonMinWidth); |
| 135 return preferred_size; | 189 return preferred_size; |
| 136 } | 190 } |
| 137 | 191 |
| 138 } // namespace login | 192 } // namespace login |
| 139 | 193 |
| 140 } // namespace chromeos | 194 } // namespace chromeos |
| 141 | |
| OLD | NEW |