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 ThrobberHost::ThrobberHost(views::View* host_view) | |
| 72 : host_view_(host_view), throbber_widget_(NULL) { | |
|
whywhat
2010/12/13 16:10:55
Add two spaces in front of : and put the second me
altimofeev
2010/12/14 11:15:21
Done.
| |
| 73 } | |
| 74 | |
| 75 ThrobberHost::~ThrobberHost() { | |
| 76 StopThrobber(); | |
| 77 } | |
| 78 | |
| 79 void ThrobberHost::StartThrobber() { | |
| 80 StopThrobber(); | |
| 81 views::Widget* widget = host_view_->GetWidget(); | |
| 82 if (widget) { | |
| 83 views::Throbber* throbber = CreateDefaultSmoothedThrobber(); | |
| 84 gfx::Rect throbber_bounds = CalculateThrobberBounds(throbber); | |
| 85 | |
| 86 throbber_widget_ = | |
| 87 views::Widget::CreatePopupWidget(views::Widget::Transparent, | |
| 88 views::Widget::NotAcceptEvents, | |
| 89 views::Widget::DeleteOnDestroy, | |
| 90 views::Widget::DontMirrorOriginInRTL); | |
| 91 throbber_bounds.Offset(host_view_->GetScreenBounds().origin()); | |
| 92 throbber_widget_->InitWithWidget(widget, throbber_bounds); | |
| 93 throbber_widget_->SetContentsView(throbber); | |
| 94 throbber_widget_->Show(); | |
| 95 throbber->Start(); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 void ThrobberHost::StopThrobber() { | |
| 100 if (throbber_widget_) { | |
| 101 throbber_widget_->Close(); | |
| 102 throbber_widget_ = NULL; | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 gfx::Rect ThrobberHost::CalculateThrobberBounds(views::Throbber* throbber) { | |
| 107 gfx::Rect bounds(throbber->GetPreferredSize()); | |
| 108 bounds.set_x( | |
| 109 host_view_->width() - login::kThrobberRightMargin - bounds.width()); | |
| 110 bounds.set_y((host_view_->height() - bounds.height()) / 2); | |
| 111 return bounds; | |
| 112 } | |
| 113 | |
| 70 views::Throbber* CreateDefaultSmoothedThrobber() { | 114 views::Throbber* CreateDefaultSmoothedThrobber() { |
| 71 views::SmoothedThrobber* throbber = | 115 views::SmoothedThrobber* throbber = |
| 72 new views::SmoothedThrobber(kThrobberFrameMs); | 116 new views::SmoothedThrobber(kThrobberFrameMs); |
| 73 throbber->SetFrames( | 117 throbber->SetFrames( |
| 74 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); | 118 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); |
| 75 throbber->set_start_delay_ms(kThrobberStartDelayMs); | 119 throbber->set_start_delay_ms(kThrobberStartDelayMs); |
| 76 return throbber; | 120 return throbber; |
| 77 } | 121 } |
| 78 | 122 |
| 79 views::Throbber* CreateDefaultThrobber() { | 123 views::Throbber* CreateDefaultThrobber() { |
| 80 views::Throbber* throbber = new views::Throbber(kThrobberFrameMs, false); | 124 views::Throbber* throbber = new views::Throbber(kThrobberFrameMs, false); |
| 81 throbber->SetFrames( | 125 throbber->SetFrames( |
| 82 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); | 126 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); |
| 83 return throbber; | 127 return throbber; |
| 84 } | 128 } |
| 85 | 129 |
| 86 views::Painter* CreateBackgroundPainter() { | 130 views::Painter* CreateBackgroundPainter() { |
| 87 return new BackgroundPainter(); | 131 return new BackgroundPainter(); |
| 88 } | 132 } |
| 89 | 133 |
| 90 gfx::Rect CalculateScreenBounds(const gfx::Size& size) { | 134 gfx::Rect CalculateScreenBounds(const gfx::Size& size) { |
| 91 gfx::Rect bounds(views::Screen::GetMonitorWorkAreaNearestWindow(NULL)); | 135 gfx::Rect bounds(views::Screen::GetMonitorWorkAreaNearestWindow(NULL)); |
| 92 if (!size.IsEmpty()) { | 136 if (!size.IsEmpty()) { |
| 93 int horizontal_diff = bounds.width() - size.width(); | 137 int horizontal_diff = bounds.width() - size.width(); |
| 94 int vertical_diff = bounds.height() - size.height(); | 138 int vertical_diff = bounds.height() - size.height(); |
| 95 bounds.Inset(horizontal_diff / 2, vertical_diff / 2); | 139 bounds.Inset(horizontal_diff / 2, vertical_diff / 2); |
| 96 } | 140 } |
| 97 | |
| 98 return bounds; | 141 return bounds; |
| 99 } | 142 } |
| 100 | 143 |
| 101 void CorrectLabelFontSize(views::Label* label) { | 144 void CorrectLabelFontSize(views::Label* label) { |
| 102 if (label) | 145 if (label) |
| 103 label->SetFont(label->font().DeriveFont(kFontSizeCorrectionDelta)); | 146 label->SetFont(label->font().DeriveFont(kFontSizeCorrectionDelta)); |
| 104 } | 147 } |
| 105 | 148 |
| 106 void CorrectMenuButtonFontSize(views::MenuButton* button) { | 149 void CorrectMenuButtonFontSize(views::MenuButton* button) { |
| 107 if (button) | 150 if (button) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 131 gfx::Size preferred_size = NativeButton::GetPreferredSize(); | 174 gfx::Size preferred_size = NativeButton::GetPreferredSize(); |
| 132 // Set minimal width. | 175 // Set minimal width. |
| 133 if (preferred_size.width() < kButtonMinWidth) | 176 if (preferred_size.width() < kButtonMinWidth) |
| 134 preferred_size.set_width(kButtonMinWidth); | 177 preferred_size.set_width(kButtonMinWidth); |
| 135 return preferred_size; | 178 return preferred_size; |
| 136 } | 179 } |
| 137 | 180 |
| 138 } // namespace login | 181 } // namespace login |
| 139 | 182 |
| 140 } // namespace chromeos | 183 } // namespace chromeos |
| 141 | |
| OLD | NEW |