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